config.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. #ifndef WASM_ENABLE_WORD_ALIGN_READ
  66. #define WASM_ENABLE_WORD_ALIGN_READ 0
  67. #endif
  68. #define AOT_MAGIC_NUMBER 0x746f6100
  69. #define AOT_CURRENT_VERSION 3
  70. #ifndef WASM_ENABLE_JIT
  71. #define WASM_ENABLE_JIT 0
  72. #endif
  73. #ifndef WASM_ENABLE_LAZY_JIT
  74. #define WASM_ENABLE_LAZY_JIT 0
  75. #endif
  76. #ifndef WASM_ORC_JIT_BACKEND_THREAD_NUM
  77. /* The number of backend threads created by runtime */
  78. #define WASM_ORC_JIT_BACKEND_THREAD_NUM 4
  79. #endif
  80. #if WASM_ORC_JIT_BACKEND_THREAD_NUM < 1
  81. #error "WASM_ORC_JIT_BACKEND_THREAD_NUM must be greater than 0"
  82. #endif
  83. #ifndef WASM_ORC_JIT_COMPILE_THREAD_NUM
  84. /* The number of compilation threads created by LLVM JIT */
  85. #define WASM_ORC_JIT_COMPILE_THREAD_NUM 4
  86. #endif
  87. #if WASM_ORC_JIT_COMPILE_THREAD_NUM < 1
  88. #error "WASM_ORC_JIT_COMPILE_THREAD_NUM must be greater than 0"
  89. #endif
  90. #if (WASM_ENABLE_AOT == 0) && (WASM_ENABLE_JIT != 0)
  91. /* LLVM JIT can only be enabled when AOT is enabled */
  92. #undef WASM_ENABLE_JIT
  93. #define WASM_ENABLE_JIT 0
  94. #undef WASM_ENABLE_LAZY_JIT
  95. #define WASM_ENABLE_LAZY_JIT 0
  96. #endif
  97. #ifndef WASM_ENABLE_FAST_JIT
  98. #define WASM_ENABLE_FAST_JIT 0
  99. #endif
  100. #ifndef WASM_ENABLE_FAST_JIT_DUMP
  101. #define WASM_ENABLE_FAST_JIT_DUMP 0
  102. #endif
  103. #ifndef FAST_JIT_DEFAULT_CODE_CACHE_SIZE
  104. #define FAST_JIT_DEFAULT_CODE_CACHE_SIZE 10 * 1024 * 1024
  105. #endif
  106. #ifndef WASM_ENABLE_WAMR_COMPILER
  107. #define WASM_ENABLE_WAMR_COMPILER 0
  108. #endif
  109. #ifndef WASM_ENABLE_LIBC_BUILTIN
  110. #define WASM_ENABLE_LIBC_BUILTIN 0
  111. #endif
  112. #ifndef WASM_ENABLE_LIBC_WASI
  113. #define WASM_ENABLE_LIBC_WASI 0
  114. #endif
  115. #ifndef WASM_ENABLE_UVWASI
  116. #define WASM_ENABLE_UVWASI 0
  117. #endif
  118. #ifndef WASM_ENABLE_WASI_NN
  119. #define WASM_ENABLE_WASI_NN 0
  120. #endif
  121. #ifndef WASM_ENABLE_WASI_NN_GPU
  122. #define WASM_ENABLE_WASI_NN_GPU 0
  123. #endif
  124. #ifndef WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE
  125. #define WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE 0
  126. #endif
  127. /* Default disable libc emcc */
  128. #ifndef WASM_ENABLE_LIBC_EMCC
  129. #define WASM_ENABLE_LIBC_EMCC 0
  130. #endif
  131. #ifndef WASM_ENABLE_LIB_RATS
  132. #define WASM_ENABLE_LIB_RATS 0
  133. #endif
  134. #ifndef WASM_ENABLE_LIB_PTHREAD
  135. #define WASM_ENABLE_LIB_PTHREAD 0
  136. #endif
  137. #ifndef WASM_ENABLE_LIB_PTHREAD_SEMAPHORE
  138. #define WASM_ENABLE_LIB_PTHREAD_SEMAPHORE 0
  139. #endif
  140. #ifndef WASM_ENABLE_LIB_WASI_THREADS
  141. #define WASM_ENABLE_LIB_WASI_THREADS 0
  142. #endif
  143. #ifndef WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION
  144. #define WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION WASM_ENABLE_LIB_WASI_THREADS
  145. #elif WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION == 0 \
  146. && WASM_ENABLE_LIB_WASI_THREADS == 1
  147. #error "Heap aux stack allocation must be enabled for WASI threads"
  148. #endif
  149. #ifndef WASM_ENABLE_BASE_LIB
  150. #define WASM_ENABLE_BASE_LIB 0
  151. #endif
  152. #ifndef WASM_ENABLE_APP_FRAMEWORK
  153. #define WASM_ENABLE_APP_FRAMEWORK 0
  154. #endif
  155. #ifndef WASM_HAVE_MREMAP
  156. #define WASM_HAVE_MREMAP 0
  157. #endif
  158. /* Bulk memory operation */
  159. #ifndef WASM_ENABLE_BULK_MEMORY
  160. #define WASM_ENABLE_BULK_MEMORY 0
  161. #endif
  162. /* Shared memory */
  163. #ifndef WASM_ENABLE_SHARED_MEMORY
  164. #define WASM_ENABLE_SHARED_MEMORY 0
  165. #endif
  166. /* Thread manager */
  167. #ifndef WASM_ENABLE_THREAD_MGR
  168. #define WASM_ENABLE_THREAD_MGR 0
  169. #endif
  170. /* Source debugging */
  171. #ifndef WASM_ENABLE_DEBUG_INTERP
  172. #define WASM_ENABLE_DEBUG_INTERP 0
  173. #endif
  174. #if WASM_ENABLE_DEBUG_INTERP != 0
  175. #ifndef DEBUG_EXECUTION_MEMORY_SIZE
  176. /* 0x85000 is the size required by lldb, if this is changed to a smaller value,
  177. * then the debugger will not be able to evaluate user expressions, other
  178. * functionality such as breakpoint and stepping are not influenced by this */
  179. #define DEBUG_EXECUTION_MEMORY_SIZE 0x85000
  180. #endif
  181. #endif /* end of WASM_ENABLE_DEBUG_INTERP != 0 */
  182. #ifndef WASM_ENABLE_DEBUG_AOT
  183. #define WASM_ENABLE_DEBUG_AOT 0
  184. #endif
  185. /* Custom sections */
  186. #ifndef WASM_ENABLE_LOAD_CUSTOM_SECTION
  187. #define WASM_ENABLE_LOAD_CUSTOM_SECTION 0
  188. #endif
  189. /* WASM log system */
  190. #ifndef WASM_ENABLE_LOG
  191. #define WASM_ENABLE_LOG 1
  192. #endif
  193. /* When this flag is set, WAMR will not automatically
  194. * initialize sockets on Windows platforms. The host
  195. * application is responsible for calling WSAStartup()
  196. * before executing WAMR code that uses sockets, and
  197. * calling WSACleanup() after.
  198. * This flag passes control of socket initialization from
  199. * WAMR to the host application. */
  200. #ifndef WASM_ENABLE_HOST_SOCKET_INIT
  201. #define WASM_ENABLE_HOST_SOCKET_INIT 0
  202. #endif
  203. #ifndef WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS
  204. #if defined(BUILD_TARGET_X86_32) || defined(BUILD_TARGET_X86_64) \
  205. || defined(BUILD_TARGET_AARCH64)
  206. #define WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS 1
  207. #else
  208. #define WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS 0
  209. #endif
  210. #endif
  211. /* WASM Interpreter labels-as-values feature */
  212. #ifndef WASM_ENABLE_LABELS_AS_VALUES
  213. #ifdef __GNUC__
  214. #define WASM_ENABLE_LABELS_AS_VALUES 1
  215. #else
  216. #define WASM_ENABLE_LABELS_AS_VALUES 0
  217. #endif
  218. #endif
  219. /* Enable fast interpreter or not */
  220. #ifndef WASM_ENABLE_FAST_INTERP
  221. #define WASM_ENABLE_FAST_INTERP 0
  222. #endif
  223. #if WASM_ENABLE_FAST_INTERP != 0
  224. #define WASM_DEBUG_PREPROCESSOR 0
  225. #endif
  226. /* Enable opcode counter or not */
  227. #ifndef WASM_ENABLE_OPCODE_COUNTER
  228. #define WASM_ENABLE_OPCODE_COUNTER 0
  229. #endif
  230. /* Support a module with dependency, other modules */
  231. #ifndef WASM_ENABLE_MULTI_MODULE
  232. #define WASM_ENABLE_MULTI_MODULE 0
  233. #endif
  234. /* Enable wasm mini loader or not */
  235. #ifndef WASM_ENABLE_MINI_LOADER
  236. #define WASM_ENABLE_MINI_LOADER 0
  237. #endif
  238. /* Disable boundary check with hardware trap or not,
  239. * enable it by default if it is supported */
  240. #ifndef WASM_DISABLE_HW_BOUND_CHECK
  241. #define WASM_DISABLE_HW_BOUND_CHECK 0
  242. #endif
  243. /* Disable native stack access boundary check with hardware
  244. * trap or not, enable it by default if it is supported */
  245. #ifndef WASM_DISABLE_STACK_HW_BOUND_CHECK
  246. #define WASM_DISABLE_STACK_HW_BOUND_CHECK 0
  247. #endif
  248. /* Disable SIMD unless it is manualy enabled somewhere */
  249. #ifndef WASM_ENABLE_SIMD
  250. #define WASM_ENABLE_SIMD 0
  251. #endif
  252. /* Memory profiling */
  253. #ifndef WASM_ENABLE_MEMORY_PROFILING
  254. #define WASM_ENABLE_MEMORY_PROFILING 0
  255. #endif
  256. /* Memory tracing */
  257. #ifndef WASM_ENABLE_MEMORY_TRACING
  258. #define WASM_ENABLE_MEMORY_TRACING 0
  259. #endif
  260. /* Performance profiling */
  261. #ifndef WASM_ENABLE_PERF_PROFILING
  262. #define WASM_ENABLE_PERF_PROFILING 0
  263. #endif
  264. /* Dump call stack */
  265. #ifndef WASM_ENABLE_DUMP_CALL_STACK
  266. #define WASM_ENABLE_DUMP_CALL_STACK 0
  267. #endif
  268. /* Heap verification */
  269. #ifndef BH_ENABLE_GC_VERIFY
  270. #define BH_ENABLE_GC_VERIFY 0
  271. #endif
  272. /* Heap corruption check, enabled by default */
  273. #ifndef BH_ENABLE_GC_CORRUPTION_CHECK
  274. #define BH_ENABLE_GC_CORRUPTION_CHECK 1
  275. #endif
  276. /* Enable global heap pool if heap verification is enabled */
  277. #if BH_ENABLE_GC_VERIFY != 0
  278. #define WASM_ENABLE_GLOBAL_HEAP_POOL 1
  279. #endif
  280. /* Global heap pool */
  281. #ifndef WASM_ENABLE_GLOBAL_HEAP_POOL
  282. #define WASM_ENABLE_GLOBAL_HEAP_POOL 0
  283. #endif
  284. #ifndef WASM_ENABLE_SPEC_TEST
  285. #define WASM_ENABLE_SPEC_TEST 0
  286. #endif
  287. /* Global heap pool size in bytes */
  288. #ifndef WASM_GLOBAL_HEAP_SIZE
  289. #define WASM_GLOBAL_HEAP_SIZE (10 * 1024 * 1024)
  290. #endif
  291. /* Max app number of all modules */
  292. #define MAX_APP_INSTALLATIONS 3
  293. /* Default timer number in one app */
  294. #define DEFAULT_TIMERS_PER_APP 20
  295. /* Max timer number in one app */
  296. #define MAX_TIMERS_PER_APP 30
  297. /* Max connection number in one app */
  298. #define MAX_CONNECTION_PER_APP 20
  299. /* Max resource registration number in one app */
  300. #define RESOURCE_REGISTRATION_NUM_MAX 16
  301. /* Max length of resource/event url */
  302. #define RESOUCE_EVENT_URL_LEN_MAX 256
  303. /* Default length of queue */
  304. #define DEFAULT_QUEUE_LENGTH 50
  305. /* Default watchdog interval in ms */
  306. #define DEFAULT_WATCHDOG_INTERVAL (3 * 60 * 1000)
  307. /* The max percentage of global heap that app memory space can grow */
  308. #define APP_MEMORY_MAX_GLOBAL_HEAP_PERCENT 1 / 3
  309. /* Default min/max heap size of each app */
  310. #ifndef APP_HEAP_SIZE_DEFAULT
  311. #define APP_HEAP_SIZE_DEFAULT (8 * 1024)
  312. #endif
  313. #define APP_HEAP_SIZE_MIN (256)
  314. #define APP_HEAP_SIZE_MAX (512 * 1024 * 1024)
  315. /* Default wasm stack size of each app */
  316. #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
  317. #define DEFAULT_WASM_STACK_SIZE (16 * 1024)
  318. #else
  319. #define DEFAULT_WASM_STACK_SIZE (12 * 1024)
  320. #endif
  321. /* Min auxilliary stack size of each wasm thread */
  322. #define WASM_THREAD_AUX_STACK_SIZE_MIN (256)
  323. /* Default/min native stack size of each app thread */
  324. #if !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
  325. && defined(APP_THREAD_STACK_SIZE_MIN))
  326. #if defined(BH_PLATFORM_ZEPHYR) || defined(BH_PLATFORM_ALIOS_THINGS) \
  327. || defined(BH_PLATFORM_ESP_IDF) || defined(BH_PLATFORM_OPENRTOS)
  328. #define APP_THREAD_STACK_SIZE_DEFAULT (6 * 1024)
  329. #define APP_THREAD_STACK_SIZE_MIN (4 * 1024)
  330. #elif defined(PTHREAD_STACK_DEFAULT) && defined(PTHREAD_STACK_MIN)
  331. #define APP_THREAD_STACK_SIZE_DEFAULT PTHREAD_STACK_DEFAULT
  332. #define APP_THREAD_STACK_SIZE_MIN PTHREAD_STACK_MIN
  333. #elif WASM_ENABLE_UVWASI != 0
  334. /* UVWASI requires larger native stack */
  335. #define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
  336. #define APP_THREAD_STACK_SIZE_MIN (48 * 1024)
  337. #else
  338. #define APP_THREAD_STACK_SIZE_DEFAULT (128 * 1024)
  339. #define APP_THREAD_STACK_SIZE_MIN (24 * 1024)
  340. #endif
  341. #endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
  342. && defined(APP_THREAD_STACK_SIZE_MIN)) */
  343. /* Max native stack size of each app thread */
  344. #if !defined(APP_THREAD_STACK_SIZE_MAX)
  345. #define APP_THREAD_STACK_SIZE_MAX (8 * 1024 * 1024)
  346. #endif
  347. /* Reserved bytes to the native thread stack boundary, throw native
  348. stack overflow exception if the guard boudary is reached */
  349. #ifndef WASM_STACK_GUARD_SIZE
  350. #if WASM_ENABLE_UVWASI != 0
  351. /* UVWASI requires larger native stack */
  352. #define WASM_STACK_GUARD_SIZE (4096 * 6)
  353. #else
  354. #define WASM_STACK_GUARD_SIZE (1024)
  355. #endif
  356. #endif
  357. /* Guard page count for stack overflow check with hardware trap */
  358. #ifndef STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT
  359. #define STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT 3
  360. #endif
  361. /* Default wasm block address cache size and conflict list size */
  362. #ifndef BLOCK_ADDR_CACHE_SIZE
  363. #define BLOCK_ADDR_CACHE_SIZE 64
  364. #endif
  365. #define BLOCK_ADDR_CONFLICT_SIZE 2
  366. /* Default max thread num per cluster. Can be overwrite by
  367. wasm_runtime_set_max_thread_num */
  368. #define CLUSTER_MAX_THREAD_NUM 4
  369. #ifndef WASM_ENABLE_TAIL_CALL
  370. #define WASM_ENABLE_TAIL_CALL 0
  371. #endif
  372. #ifndef WASM_ENABLE_CUSTOM_NAME_SECTION
  373. #define WASM_ENABLE_CUSTOM_NAME_SECTION 0
  374. #endif
  375. #ifndef WASM_ENABLE_REF_TYPES
  376. #define WASM_ENABLE_REF_TYPES 0
  377. #endif
  378. #ifndef WASM_ENABLE_EXCE_HANDLING
  379. #define WASM_ENABLE_EXCE_HANDLING 0
  380. #endif
  381. #ifndef WASM_ENABLE_TAGS
  382. #define WASM_ENABLE_TAGS 0
  383. #endif
  384. #ifndef WASM_ENABLE_SGX_IPFS
  385. #define WASM_ENABLE_SGX_IPFS 0
  386. #endif
  387. #ifndef WASM_MEM_ALLOC_WITH_USER_DATA
  388. #define WASM_MEM_ALLOC_WITH_USER_DATA 0
  389. #endif
  390. #ifndef WASM_ENABLE_WASM_CACHE
  391. #define WASM_ENABLE_WASM_CACHE 0
  392. #endif
  393. #ifndef WASM_ENABLE_STATIC_PGO
  394. #define WASM_ENABLE_STATIC_PGO 0
  395. #endif
  396. /* Disable writing linear memory base address to GS segment register,
  397. by default only in linux x86-64, linear memory base addr is written
  398. to GS segment register before calling wasm/aot function. */
  399. #ifndef WASM_DISABLE_WRITE_GS_BASE
  400. #define WASM_DISABLE_WRITE_GS_BASE 0
  401. #endif
  402. /* Configurable bounds checks */
  403. #ifndef WASM_CONFIGURABLE_BOUNDS_CHECKS
  404. #define WASM_CONFIGURABLE_BOUNDS_CHECKS 0
  405. #endif
  406. /* Some chip cannot support external ram with rwx attr at the same time,
  407. it has to map it into 2 spaces of idbus and dbus, code in dbus can be
  408. read/written and read/executed in ibus. so there are 2 steps to execute
  409. the code, first, copy & do relocation in dbus space, and second execute
  410. it in ibus space, since in the 2 spaces the contents are the same,
  411. so we call it bus mirror.
  412. */
  413. #ifndef WASM_MEM_DUAL_BUS_MIRROR
  414. #define WASM_MEM_DUAL_BUS_MIRROR 0
  415. #endif
  416. /* The max number of module instance contexts. */
  417. #ifndef WASM_MAX_INSTANCE_CONTEXTS
  418. #define WASM_MAX_INSTANCE_CONTEXTS 8
  419. #endif
  420. /* linux perf support */
  421. #ifndef WASM_ENABLE_LINUX_PERF
  422. #define WASM_ENABLE_LINUX_PERF 0
  423. #endif
  424. /* Support registering quick AOT/JIT function entries of some func types
  425. to speedup the calling process of invoking the AOT/JIT functions of
  426. these types from the host embedder */
  427. #ifndef WASM_ENABLE_QUICK_AOT_ENTRY
  428. #define WASM_ENABLE_QUICK_AOT_ENTRY 1
  429. #endif
  430. #endif /* end of _CONFIG_H_ */