config.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _CONFIG_H_
  6. #define _CONFIG_H_
  7. /* clang-format off */
  8. #if !defined(BUILD_TARGET_X86_64) \
  9. && !defined(BUILD_TARGET_AMD_64) \
  10. && !defined(BUILD_TARGET_AARCH64) \
  11. && !defined(BUILD_TARGET_X86_32) \
  12. && !defined(BUILD_TARGET_ARM) \
  13. && !defined(BUILD_TARGET_ARM_VFP) \
  14. && !defined(BUILD_TARGET_THUMB) \
  15. && !defined(BUILD_TARGET_THUMB_VFP) \
  16. && !defined(BUILD_TARGET_MIPS) \
  17. && !defined(BUILD_TARGET_XTENSA) \
  18. && !defined(BUILD_TARGET_RISCV64_LP64D) \
  19. && !defined(BUILD_TARGET_RISCV64_LP64) \
  20. && !defined(BUILD_TARGET_RISCV32_ILP32D) \
  21. && !defined(BUILD_TARGET_RISCV32_ILP32) \
  22. && !defined(BUILD_TARGET_ARC)
  23. /* clang-format on */
  24. #if defined(__x86_64__) || defined(__x86_64)
  25. #define BUILD_TARGET_X86_64
  26. #elif defined(__amd64__) || defined(__amd64)
  27. #define BUILD_TARGET_AMD_64
  28. #elif defined(__aarch64__)
  29. #define BUILD_TARGET_AARCH64
  30. #elif defined(__i386__) || defined(__i386) || defined(i386)
  31. #define BUILD_TARGET_X86_32
  32. #elif defined(__thumb__)
  33. #define BUILD_TARGET_THUMB
  34. #define BUILD_TARGET "THUMBV4T"
  35. #elif defined(__arm__)
  36. #define BUILD_TARGET_ARM
  37. #define BUILD_TARGET "ARMV4T"
  38. #elif defined(__mips__) || defined(__mips) || defined(mips)
  39. #define BUILD_TARGET_MIPS
  40. #elif defined(__XTENSA__)
  41. #define BUILD_TARGET_XTENSA
  42. #elif defined(__riscv) && (__riscv_xlen == 64)
  43. #define BUILD_TARGET_RISCV64_LP64D
  44. #elif defined(__riscv) && (__riscv_xlen == 32)
  45. #define BUILD_TARGET_RISCV32_ILP32D
  46. #elif defined(__arc__)
  47. #define BUILD_TARGET_ARC
  48. #else
  49. #error "Build target isn't set"
  50. #endif
  51. #endif
  52. #ifndef BH_DEBUG
  53. #define BH_DEBUG 0
  54. #endif
  55. #define MEM_ALLOCATOR_EMS 0
  56. #define MEM_ALLOCATOR_TLSF 1
  57. /* Default memory allocator */
  58. #define DEFAULT_MEM_ALLOCATOR MEM_ALLOCATOR_EMS
  59. #ifndef WASM_ENABLE_INTERP
  60. #define WASM_ENABLE_INTERP 0
  61. #endif
  62. #ifndef WASM_ENABLE_AOT
  63. #define WASM_ENABLE_AOT 0
  64. #endif
  65. #define AOT_MAGIC_NUMBER 0x746f6100
  66. #define AOT_CURRENT_VERSION 3
  67. #ifndef WASM_ENABLE_JIT
  68. #define WASM_ENABLE_JIT 0
  69. #endif
  70. #ifndef WASM_ENABLE_LAZY_JIT
  71. #define WASM_ENABLE_LAZY_JIT 0
  72. #endif
  73. #ifndef WASM_LAZY_JIT_COMPILE_THREAD_NUM
  74. #define WASM_LAZY_JIT_COMPILE_THREAD_NUM 4
  75. #endif
  76. #if (WASM_ENABLE_AOT == 0) && (WASM_ENABLE_JIT != 0)
  77. /* LazyJIT or MCJIT can only be enabled when AOT is enabled */
  78. #undef WASM_ENABLE_JIT
  79. #define WASM_ENABLE_JIT 0
  80. #undef WASM_ENABLE_LAZY_JIT
  81. #define WASM_ENABLE_LAZY_JIT 0
  82. #endif
  83. #ifndef WASM_ENABLE_FAST_JIT
  84. #define WASM_ENABLE_FAST_JIT 0
  85. #endif
  86. #ifndef WASM_ENABLE_FAST_JIT_DUMP
  87. #define WASM_ENABLE_FAST_JIT_DUMP 0
  88. #endif
  89. #ifndef FAST_JIT_DEFAULT_CODE_CACHE_SIZE
  90. #define FAST_JIT_DEFAULT_CODE_CACHE_SIZE 10 * 1024 * 1024
  91. #endif
  92. #ifndef WASM_ENABLE_WAMR_COMPILER
  93. #define WASM_ENABLE_WAMR_COMPILER 0
  94. #endif
  95. #if WASM_ENABLE_WAMR_COMPILER != 0
  96. #ifndef WASM_ENABLE_LLVM_LEGACY_PM
  97. /* Whether to use LLVM legacy pass manager when building wamrc,
  98. by default it is disabled and LLVM new pass manager is used */
  99. #define WASM_ENABLE_LLVM_LEGACY_PM 0
  100. #endif
  101. #endif
  102. #ifndef WASM_ENABLE_LIBC_BUILTIN
  103. #define WASM_ENABLE_LIBC_BUILTIN 0
  104. #endif
  105. #ifndef WASM_ENABLE_LIBC_WASI
  106. #define WASM_ENABLE_LIBC_WASI 0
  107. #endif
  108. #ifndef WASM_ENABLE_UVWASI
  109. #define WASM_ENABLE_UVWASI 0
  110. #endif
  111. /* Default disable libc emcc */
  112. #ifndef WASM_ENABLE_LIBC_EMCC
  113. #define WASM_ENABLE_LIBC_EMCC 0
  114. #endif
  115. #ifndef WASM_ENABLE_LIB_RATS
  116. #define WASM_ENABLE_LIB_RATS 0
  117. #endif
  118. #ifndef WASM_ENABLE_LIB_PTHREAD
  119. #define WASM_ENABLE_LIB_PTHREAD 0
  120. #endif
  121. #ifndef WASM_ENABLE_LIB_PTHREAD_SEMAPHORE
  122. #define WASM_ENABLE_LIB_PTHREAD_SEMAPHORE 0
  123. #endif
  124. #ifndef WASM_ENABLE_BASE_LIB
  125. #define WASM_ENABLE_BASE_LIB 0
  126. #endif
  127. #ifndef WASM_ENABLE_APP_FRAMEWORK
  128. #define WASM_ENABLE_APP_FRAMEWORK 0
  129. #endif
  130. /* Bulk memory operation */
  131. #ifndef WASM_ENABLE_BULK_MEMORY
  132. #define WASM_ENABLE_BULK_MEMORY 0
  133. #endif
  134. /* Shared memory */
  135. #ifndef WASM_ENABLE_SHARED_MEMORY
  136. #define WASM_ENABLE_SHARED_MEMORY 0
  137. #endif
  138. /* Thread manager */
  139. #ifndef WASM_ENABLE_THREAD_MGR
  140. #define WASM_ENABLE_THREAD_MGR 0
  141. #endif
  142. /* Source debugging */
  143. #ifndef WASM_ENABLE_DEBUG_INTERP
  144. #define WASM_ENABLE_DEBUG_INTERP 0
  145. #endif
  146. #if WASM_ENABLE_DEBUG_INTERP != 0
  147. #ifndef DEBUG_EXECUTION_MEMORY_SIZE
  148. /* 0x85000 is the size required by lldb, if this is changed to a smaller value,
  149. * then the debugger will not be able to evaluate user expressions, other
  150. * functionality such as breakpoint and stepping are not influenced by this */
  151. #define DEBUG_EXECUTION_MEMORY_SIZE 0x85000
  152. #endif
  153. #endif /* end of WASM_ENABLE_DEBUG_INTERP != 0 */
  154. #ifndef WASM_ENABLE_DEBUG_AOT
  155. #define WASM_ENABLE_DEBUG_AOT 0
  156. #endif
  157. /* Custom sections */
  158. #ifndef WASM_ENABLE_LOAD_CUSTOM_SECTION
  159. #define WASM_ENABLE_LOAD_CUSTOM_SECTION 0
  160. #endif
  161. /* WASM log system */
  162. #ifndef WASM_ENABLE_LOG
  163. #define WASM_ENABLE_LOG 1
  164. #endif
  165. #ifndef WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS
  166. #if defined(BUILD_TARGET_X86_32) || defined(BUILD_TARGET_X86_64) \
  167. || defined(BUILD_TARGET_AARCH64)
  168. #define WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS 1
  169. #else
  170. #define WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS 0
  171. #endif
  172. #endif
  173. /* WASM Interpreter labels-as-values feature */
  174. #ifndef WASM_ENABLE_LABELS_AS_VALUES
  175. #ifdef __GNUC__
  176. #define WASM_ENABLE_LABELS_AS_VALUES 1
  177. #else
  178. #define WASM_ENABLE_LABELS_AS_VALUES 0
  179. #endif
  180. #endif
  181. /* Enable fast interpreter or not */
  182. #ifndef WASM_ENABLE_FAST_INTERP
  183. #define WASM_ENABLE_FAST_INTERP 0
  184. #endif
  185. #if WASM_ENABLE_FAST_INTERP != 0
  186. #define WASM_DEBUG_PREPROCESSOR 0
  187. #endif
  188. /* Enable opcode counter or not */
  189. #ifndef WASM_ENABLE_OPCODE_COUNTER
  190. #define WASM_ENABLE_OPCODE_COUNTER 0
  191. #endif
  192. /* Support a module with dependency, other modules */
  193. #ifndef WASM_ENABLE_MULTI_MODULE
  194. #define WASM_ENABLE_MULTI_MODULE 0
  195. #endif
  196. /* Enable wasm mini loader or not */
  197. #ifndef WASM_ENABLE_MINI_LOADER
  198. #define WASM_ENABLE_MINI_LOADER 0
  199. #endif
  200. /* Disable boundary check with hardware trap or not,
  201. * enable it by default if it is supported */
  202. #ifndef WASM_DISABLE_HW_BOUND_CHECK
  203. #define WASM_DISABLE_HW_BOUND_CHECK 0
  204. #endif
  205. /* Disable SIMD unless it is manualy enabled somewhere */
  206. #ifndef WASM_ENABLE_SIMD
  207. #define WASM_ENABLE_SIMD 0
  208. #endif
  209. /* Memory profiling */
  210. #ifndef WASM_ENABLE_MEMORY_PROFILING
  211. #define WASM_ENABLE_MEMORY_PROFILING 0
  212. #endif
  213. /* Memory tracing */
  214. #ifndef WASM_ENABLE_MEMORY_TRACING
  215. #define WASM_ENABLE_MEMORY_TRACING 0
  216. #endif
  217. /* Performance profiling */
  218. #ifndef WASM_ENABLE_PERF_PROFILING
  219. #define WASM_ENABLE_PERF_PROFILING 0
  220. #endif
  221. /* Dump call stack */
  222. #ifndef WASM_ENABLE_DUMP_CALL_STACK
  223. #define WASM_ENABLE_DUMP_CALL_STACK 0
  224. #endif
  225. /* Heap verification */
  226. #ifndef BH_ENABLE_GC_VERIFY
  227. #define BH_ENABLE_GC_VERIFY 0
  228. #endif
  229. /* Enable global heap pool if heap verification is enabled */
  230. #if BH_ENABLE_GC_VERIFY != 0
  231. #define WASM_ENABLE_GLOBAL_HEAP_POOL 1
  232. #endif
  233. /* Global heap pool */
  234. #ifndef WASM_ENABLE_GLOBAL_HEAP_POOL
  235. #define WASM_ENABLE_GLOBAL_HEAP_POOL 0
  236. #endif
  237. #ifndef WASM_ENABLE_SPEC_TEST
  238. #define WASM_ENABLE_SPEC_TEST 0
  239. #endif
  240. /* Global heap pool size in bytes */
  241. #ifndef WASM_GLOBAL_HEAP_SIZE
  242. #if WASM_ENABLE_SPEC_TEST != 0
  243. /* Spec test requires more heap pool size */
  244. #define WASM_GLOBAL_HEAP_SIZE (300 * 1024 * 1024)
  245. #else
  246. #define WASM_GLOBAL_HEAP_SIZE (10 * 1024 * 1024)
  247. #endif
  248. #endif
  249. /* Max app number of all modules */
  250. #define MAX_APP_INSTALLATIONS 3
  251. /* Default timer number in one app */
  252. #define DEFAULT_TIMERS_PER_APP 20
  253. /* Max timer number in one app */
  254. #define MAX_TIMERS_PER_APP 30
  255. /* Max connection number in one app */
  256. #define MAX_CONNECTION_PER_APP 20
  257. /* Max resource registration number in one app */
  258. #define RESOURCE_REGISTRATION_NUM_MAX 16
  259. /* Max length of resource/event url */
  260. #define RESOUCE_EVENT_URL_LEN_MAX 256
  261. /* Default length of queue */
  262. #define DEFAULT_QUEUE_LENGTH 50
  263. /* Default watchdog interval in ms */
  264. #define DEFAULT_WATCHDOG_INTERVAL (3 * 60 * 1000)
  265. /* The max percentage of global heap that app memory space can grow */
  266. #define APP_MEMORY_MAX_GLOBAL_HEAP_PERCENT 1 / 3
  267. /* Default min/max heap size of each app */
  268. #ifndef APP_HEAP_SIZE_DEFAULT
  269. #define APP_HEAP_SIZE_DEFAULT (8 * 1024)
  270. #endif
  271. #define APP_HEAP_SIZE_MIN (256)
  272. #define APP_HEAP_SIZE_MAX (512 * 1024 * 1024)
  273. /* Default wasm stack size of each app */
  274. #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
  275. #define DEFAULT_WASM_STACK_SIZE (16 * 1024)
  276. #else
  277. #define DEFAULT_WASM_STACK_SIZE (12 * 1024)
  278. #endif
  279. /* Min auxilliary stack size of each wasm thread */
  280. #define WASM_THREAD_AUX_STACK_SIZE_MIN (256)
  281. /* Default/min native stack size of each app thread */
  282. #if !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
  283. && defined(APP_THREAD_STACK_SIZE_MIN))
  284. #if defined(BH_PLATFORM_ZEPHYR) || defined(BH_PLATFORM_ALIOS_THINGS) \
  285. || defined(BH_PLATFORM_ESP_IDF) || defined(BH_PLATFORM_OPENRTOS)
  286. #define APP_THREAD_STACK_SIZE_DEFAULT (6 * 1024)
  287. #define APP_THREAD_STACK_SIZE_MIN (4 * 1024)
  288. #elif defined(PTHREAD_STACK_DEFAULT) && defined(PTHREAD_STACK_MIN)
  289. #define APP_THREAD_STACK_SIZE_DEFAULT PTHREAD_STACK_DEFAULT
  290. #define APP_THREAD_STACK_SIZE_MIN PTHREAD_STACK_MIN
  291. #elif WASM_ENABLE_UVWASI != 0
  292. /* UVWASI requires larger native stack */
  293. #define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
  294. #define APP_THREAD_STACK_SIZE_MIN (48 * 1024)
  295. #else
  296. #define APP_THREAD_STACK_SIZE_DEFAULT (32 * 1024)
  297. #define APP_THREAD_STACK_SIZE_MIN (24 * 1024)
  298. #endif
  299. #endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
  300. && defined(APP_THREAD_STACK_SIZE_MIN)) */
  301. /* Max native stack size of each app thread */
  302. #if !defined(APP_THREAD_STACK_SIZE_MAX)
  303. #define APP_THREAD_STACK_SIZE_MAX (8 * 1024 * 1024)
  304. #endif
  305. /* Reserved bytes to the native thread stack boundary, throw native
  306. stack overflow exception if the guard boudary is reached */
  307. #ifndef WASM_STACK_GUARD_SIZE
  308. #if WASM_ENABLE_UVWASI != 0
  309. /* UVWASI requires larger native stack */
  310. #define WASM_STACK_GUARD_SIZE (4096 * 6)
  311. #else
  312. #define WASM_STACK_GUARD_SIZE (1024)
  313. #endif
  314. #endif
  315. /* Guard page count for stack overflow check with hardware trap */
  316. #ifndef STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT
  317. #define STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT 3
  318. #endif
  319. /* Default wasm block address cache size and conflict list size */
  320. #ifndef BLOCK_ADDR_CACHE_SIZE
  321. #define BLOCK_ADDR_CACHE_SIZE 64
  322. #endif
  323. #define BLOCK_ADDR_CONFLICT_SIZE 2
  324. /* Default max thread num per cluster. Can be overwrite by
  325. wasm_runtime_set_max_thread_num */
  326. #define CLUSTER_MAX_THREAD_NUM 4
  327. #ifndef WASM_ENABLE_TAIL_CALL
  328. #define WASM_ENABLE_TAIL_CALL 0
  329. #endif
  330. #ifndef WASM_ENABLE_CUSTOM_NAME_SECTION
  331. #define WASM_ENABLE_CUSTOM_NAME_SECTION 0
  332. #endif
  333. #ifndef WASM_ENABLE_REF_TYPES
  334. #define WASM_ENABLE_REF_TYPES 0
  335. #endif
  336. #ifndef WASM_ENABLE_SGX_IPFS
  337. #define WASM_ENABLE_SGX_IPFS 0
  338. #endif
  339. #endif /* end of _CONFIG_H_ */