config.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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_ILP32F) \
  22. && !defined(BUILD_TARGET_RISCV32_ILP32) \
  23. && !defined(BUILD_TARGET_ARC)
  24. /* clang-format on */
  25. #if defined(__x86_64__) || defined(__x86_64)
  26. #define BUILD_TARGET_X86_64
  27. #elif defined(__amd64__) || defined(__amd64)
  28. #define BUILD_TARGET_AMD_64
  29. #elif defined(__aarch64__)
  30. #define BUILD_TARGET_AARCH64
  31. #elif defined(__i386__) || defined(__i386) || defined(i386)
  32. #define BUILD_TARGET_X86_32
  33. #elif defined(__thumb__)
  34. #define BUILD_TARGET_THUMB
  35. #define BUILD_TARGET "THUMBV4T"
  36. #elif defined(__arm__)
  37. #define BUILD_TARGET_ARM
  38. #define BUILD_TARGET "ARMV4T"
  39. #elif defined(__mips__) || defined(__mips) || defined(mips)
  40. #define BUILD_TARGET_MIPS
  41. #elif defined(__XTENSA__)
  42. #define BUILD_TARGET_XTENSA
  43. #elif defined(__riscv) && (__riscv_xlen == 64)
  44. #define BUILD_TARGET_RISCV64_LP64D
  45. #elif defined(__riscv) && (__riscv_xlen == 32) && !defined(__riscv_flen)
  46. #define BUILD_TARGET_RISCV32_ILP32
  47. #elif defined(__riscv) && (__riscv_xlen == 32) && (__riscv_flen == 32)
  48. #define BUILD_TARGET_RISCV32_ILP32F
  49. #elif defined(__riscv) && (__riscv_xlen == 32) && (__riscv_flen == 64)
  50. #define BUILD_TARGET_RISCV32_ILP32D
  51. #elif defined(__arc__)
  52. #define BUILD_TARGET_ARC
  53. #else
  54. #error "Build target isn't set"
  55. #endif
  56. #endif
  57. #ifndef BH_DEBUG
  58. #define BH_DEBUG 0
  59. #endif
  60. #define MEM_ALLOCATOR_EMS 0
  61. #define MEM_ALLOCATOR_TLSF 1
  62. /* Default memory allocator */
  63. #define DEFAULT_MEM_ALLOCATOR MEM_ALLOCATOR_EMS
  64. #ifndef WASM_ENABLE_INTERP
  65. #define WASM_ENABLE_INTERP 0
  66. #endif
  67. #ifndef WASM_ENABLE_AOT
  68. #define WASM_ENABLE_AOT 0
  69. #endif
  70. #ifndef WASM_ENABLE_DYNAMIC_AOT_DEBUG
  71. #define WASM_ENABLE_DYNAMIC_AOT_DEBUG 0
  72. #endif
  73. #ifndef WASM_ENABLE_WORD_ALIGN_READ
  74. #define WASM_ENABLE_WORD_ALIGN_READ 0
  75. #endif
  76. #define AOT_MAGIC_NUMBER 0x746f6100
  77. /* FIXME: maybe 5? need a discussion */
  78. #define AOT_CURRENT_VERSION 4
  79. #ifndef WASM_ENABLE_JIT
  80. #define WASM_ENABLE_JIT 0
  81. #endif
  82. #ifndef WASM_ENABLE_LAZY_JIT
  83. #define WASM_ENABLE_LAZY_JIT 0
  84. #endif
  85. #ifndef WASM_ORC_JIT_BACKEND_THREAD_NUM
  86. /* The number of backend threads created by runtime */
  87. #define WASM_ORC_JIT_BACKEND_THREAD_NUM 4
  88. #endif
  89. #if WASM_ORC_JIT_BACKEND_THREAD_NUM < 1
  90. #error "WASM_ORC_JIT_BACKEND_THREAD_NUM must be greater than 0"
  91. #endif
  92. #ifndef WASM_ORC_JIT_COMPILE_THREAD_NUM
  93. /* The number of compilation threads created by LLVM JIT */
  94. #define WASM_ORC_JIT_COMPILE_THREAD_NUM 4
  95. #endif
  96. #if WASM_ORC_JIT_COMPILE_THREAD_NUM < 1
  97. #error "WASM_ORC_JIT_COMPILE_THREAD_NUM must be greater than 0"
  98. #endif
  99. #if (WASM_ENABLE_AOT == 0) && (WASM_ENABLE_JIT != 0)
  100. /* LLVM JIT can only be enabled when AOT is enabled */
  101. #undef WASM_ENABLE_JIT
  102. #define WASM_ENABLE_JIT 0
  103. #undef WASM_ENABLE_LAZY_JIT
  104. #define WASM_ENABLE_LAZY_JIT 0
  105. #endif
  106. #ifndef WASM_ENABLE_FAST_JIT
  107. #define WASM_ENABLE_FAST_JIT 0
  108. #endif
  109. #ifndef WASM_ENABLE_FAST_JIT_DUMP
  110. #define WASM_ENABLE_FAST_JIT_DUMP 0
  111. #endif
  112. #ifndef FAST_JIT_DEFAULT_CODE_CACHE_SIZE
  113. #define FAST_JIT_DEFAULT_CODE_CACHE_SIZE 10 * 1024 * 1024
  114. #endif
  115. #ifndef WASM_ENABLE_WAMR_COMPILER
  116. #define WASM_ENABLE_WAMR_COMPILER 0
  117. #endif
  118. #ifndef WASM_ENABLE_LIBC_BUILTIN
  119. #define WASM_ENABLE_LIBC_BUILTIN 0
  120. #endif
  121. #ifndef WASM_ENABLE_LIBC_WASI
  122. #define WASM_ENABLE_LIBC_WASI 0
  123. #endif
  124. #ifndef WASM_ENABLE_UVWASI
  125. #define WASM_ENABLE_UVWASI 0
  126. #endif
  127. #ifndef WASM_ENABLE_WASI_NN
  128. #define WASM_ENABLE_WASI_NN 0
  129. #endif
  130. #ifndef WASM_ENABLE_WASI_NN_GPU
  131. #define WASM_ENABLE_WASI_NN_GPU 0
  132. #endif
  133. #ifndef WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE
  134. #define WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE 0
  135. #endif
  136. #ifndef WASM_ENABLE_WASI_EPHEMERAL_NN
  137. #define WASM_ENABLE_WASI_EPHEMERAL_NN 0
  138. #endif
  139. /* Default disable libc emcc */
  140. #ifndef WASM_ENABLE_LIBC_EMCC
  141. #define WASM_ENABLE_LIBC_EMCC 0
  142. #endif
  143. #ifndef WASM_ENABLE_LIB_RATS
  144. #define WASM_ENABLE_LIB_RATS 0
  145. #endif
  146. #ifndef WASM_ENABLE_LIB_PTHREAD
  147. #define WASM_ENABLE_LIB_PTHREAD 0
  148. #endif
  149. #ifndef WASM_ENABLE_LIB_PTHREAD_SEMAPHORE
  150. #define WASM_ENABLE_LIB_PTHREAD_SEMAPHORE 0
  151. #endif
  152. #ifndef WASM_ENABLE_LIB_WASI_THREADS
  153. #define WASM_ENABLE_LIB_WASI_THREADS 0
  154. #endif
  155. #ifndef WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION
  156. #define WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION WASM_ENABLE_LIB_WASI_THREADS
  157. #elif WASM_ENABLE_HEAP_AUX_STACK_ALLOCATION == 0 \
  158. && WASM_ENABLE_LIB_WASI_THREADS == 1
  159. #error "Heap aux stack allocation must be enabled for WASI threads"
  160. #endif
  161. #ifndef WASM_ENABLE_BASE_LIB
  162. #define WASM_ENABLE_BASE_LIB 0
  163. #endif
  164. #ifndef WASM_ENABLE_APP_FRAMEWORK
  165. #define WASM_ENABLE_APP_FRAMEWORK 0
  166. #endif
  167. #ifndef WASM_HAVE_MREMAP
  168. #define WASM_HAVE_MREMAP 0
  169. #endif
  170. /* Bulk memory operation */
  171. #ifndef WASM_ENABLE_BULK_MEMORY
  172. #define WASM_ENABLE_BULK_MEMORY 0
  173. #endif
  174. /* Shared memory */
  175. #ifndef WASM_ENABLE_SHARED_MEMORY
  176. #define WASM_ENABLE_SHARED_MEMORY 0
  177. #endif
  178. /* Thread manager */
  179. #ifndef WASM_ENABLE_THREAD_MGR
  180. #define WASM_ENABLE_THREAD_MGR 0
  181. #endif
  182. /* Source debugging */
  183. #ifndef WASM_ENABLE_DEBUG_INTERP
  184. #define WASM_ENABLE_DEBUG_INTERP 0
  185. #endif
  186. #if WASM_ENABLE_DEBUG_INTERP != 0
  187. #ifndef DEBUG_EXECUTION_MEMORY_SIZE
  188. /* 0x85000 is the size required by lldb, if this is changed to a smaller value,
  189. * then the debugger will not be able to evaluate user expressions, other
  190. * functionality such as breakpoint and stepping are not influenced by this */
  191. #define DEBUG_EXECUTION_MEMORY_SIZE 0x85000
  192. #endif
  193. #endif /* end of WASM_ENABLE_DEBUG_INTERP != 0 */
  194. #ifndef WASM_ENABLE_DEBUG_AOT
  195. #define WASM_ENABLE_DEBUG_AOT 0
  196. #endif
  197. /* Custom sections */
  198. #ifndef WASM_ENABLE_LOAD_CUSTOM_SECTION
  199. #define WASM_ENABLE_LOAD_CUSTOM_SECTION 0
  200. #endif
  201. /* WASM log system */
  202. #ifndef WASM_ENABLE_LOG
  203. #define WASM_ENABLE_LOG 1
  204. #endif
  205. /* When this flag is set, WAMR will not automatically
  206. * initialize sockets on Windows platforms. The host
  207. * application is responsible for calling WSAStartup()
  208. * before executing WAMR code that uses sockets, and
  209. * calling WSACleanup() after.
  210. * This flag passes control of socket initialization from
  211. * WAMR to the host application. */
  212. #ifndef WASM_ENABLE_HOST_SOCKET_INIT
  213. #define WASM_ENABLE_HOST_SOCKET_INIT 0
  214. #endif
  215. #ifndef WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS
  216. #if defined(BUILD_TARGET_X86_32) || defined(BUILD_TARGET_X86_64) \
  217. || defined(BUILD_TARGET_AARCH64)
  218. #define WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS 1
  219. #else
  220. #define WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS 0
  221. #endif
  222. #endif
  223. /* WASM Interpreter labels-as-values feature */
  224. #ifndef WASM_ENABLE_LABELS_AS_VALUES
  225. #ifdef __GNUC__
  226. #define WASM_ENABLE_LABELS_AS_VALUES 1
  227. #else
  228. #define WASM_ENABLE_LABELS_AS_VALUES 0
  229. #endif
  230. #endif
  231. /* Enable fast interpreter or not */
  232. #ifndef WASM_ENABLE_FAST_INTERP
  233. #define WASM_ENABLE_FAST_INTERP 0
  234. #endif
  235. #if WASM_ENABLE_FAST_INTERP != 0
  236. #define WASM_DEBUG_PREPROCESSOR 0
  237. #endif
  238. /* Enable opcode counter or not */
  239. #ifndef WASM_ENABLE_OPCODE_COUNTER
  240. #define WASM_ENABLE_OPCODE_COUNTER 0
  241. #endif
  242. /* Support a module with dependency, other modules */
  243. #ifndef WASM_ENABLE_MULTI_MODULE
  244. #define WASM_ENABLE_MULTI_MODULE 0
  245. #endif
  246. /* Enable wasm mini loader or not */
  247. #ifndef WASM_ENABLE_MINI_LOADER
  248. #define WASM_ENABLE_MINI_LOADER 0
  249. #endif
  250. /* Disable boundary check with hardware trap or not,
  251. * enable it by default if it is supported */
  252. #ifndef WASM_DISABLE_HW_BOUND_CHECK
  253. #define WASM_DISABLE_HW_BOUND_CHECK 0
  254. #endif
  255. /* Disable native stack access boundary check with hardware
  256. * trap or not, enable it by default if it is supported */
  257. #ifndef WASM_DISABLE_STACK_HW_BOUND_CHECK
  258. #define WASM_DISABLE_STACK_HW_BOUND_CHECK 0
  259. #endif
  260. /* Disable SIMD unless it is manually enabled somewhere */
  261. #ifndef WASM_ENABLE_SIMD
  262. #define WASM_ENABLE_SIMD 0
  263. #endif
  264. /* GC performance profiling */
  265. #ifndef WASM_ENABLE_GC_PERF_PROFILING
  266. #define WASM_ENABLE_GC_PERF_PROFILING 0
  267. #endif
  268. /* Memory profiling */
  269. #ifndef WASM_ENABLE_MEMORY_PROFILING
  270. #define WASM_ENABLE_MEMORY_PROFILING 0
  271. #endif
  272. /* Memory tracing */
  273. #ifndef WASM_ENABLE_MEMORY_TRACING
  274. #define WASM_ENABLE_MEMORY_TRACING 0
  275. #endif
  276. /* Performance profiling */
  277. #ifndef WASM_ENABLE_PERF_PROFILING
  278. #define WASM_ENABLE_PERF_PROFILING 0
  279. #endif
  280. /* Dump call stack */
  281. #ifndef WASM_ENABLE_DUMP_CALL_STACK
  282. #define WASM_ENABLE_DUMP_CALL_STACK 0
  283. #endif
  284. /* AOT stack frame */
  285. #ifndef WASM_ENABLE_AOT_STACK_FRAME
  286. #define WASM_ENABLE_AOT_STACK_FRAME 0
  287. #endif
  288. /* Heap verification */
  289. #ifndef BH_ENABLE_GC_VERIFY
  290. #define BH_ENABLE_GC_VERIFY 0
  291. #endif
  292. /* Heap corruption check, enabled by default */
  293. #ifndef BH_ENABLE_GC_CORRUPTION_CHECK
  294. #define BH_ENABLE_GC_CORRUPTION_CHECK 1
  295. #endif
  296. /* Enable global heap pool if heap verification is enabled */
  297. #if BH_ENABLE_GC_VERIFY != 0
  298. #define WASM_ENABLE_GLOBAL_HEAP_POOL 1
  299. #endif
  300. /* Global heap pool */
  301. #ifndef WASM_ENABLE_GLOBAL_HEAP_POOL
  302. #define WASM_ENABLE_GLOBAL_HEAP_POOL 0
  303. #endif
  304. #ifndef WASM_ENABLE_SPEC_TEST
  305. #define WASM_ENABLE_SPEC_TEST 0
  306. #endif
  307. #ifndef WASM_ENABLE_WASI_TEST
  308. #define WASM_ENABLE_WASI_TEST 0
  309. #endif
  310. /* Global heap pool size in bytes */
  311. #ifndef WASM_GLOBAL_HEAP_SIZE
  312. #define WASM_GLOBAL_HEAP_SIZE (10 * 1024 * 1024)
  313. #endif
  314. /* Default length of queue */
  315. #ifndef DEFAULT_QUEUE_LENGTH
  316. #define DEFAULT_QUEUE_LENGTH 50
  317. #endif
  318. /* The max percentage of global heap that app memory space can grow */
  319. #ifndef APP_MEMORY_MAX_GLOBAL_HEAP_PERCENT
  320. #define APP_MEMORY_MAX_GLOBAL_HEAP_PERCENT 1 / 3
  321. #endif
  322. /* Default min/max heap size of each app */
  323. #ifndef APP_HEAP_SIZE_DEFAULT
  324. #define APP_HEAP_SIZE_DEFAULT (8 * 1024)
  325. #endif
  326. #define APP_HEAP_SIZE_MIN (256)
  327. /* The ems memory allocator supports maximal heap size 1GB,
  328. see ems_gc_internal.h */
  329. #define APP_HEAP_SIZE_MAX (1024 * 1024 * 1024)
  330. /* Default min/max gc heap size of each app */
  331. #ifndef GC_HEAP_SIZE_DEFAULT
  332. #define GC_HEAP_SIZE_DEFAULT (128 * 1024)
  333. #endif
  334. #define GC_HEAP_SIZE_MIN (4 * 1024)
  335. #define GC_HEAP_SIZE_MAX (1024 * 1024 * 1024)
  336. /* Default wasm stack size of each app */
  337. #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
  338. #define DEFAULT_WASM_STACK_SIZE (16 * 1024)
  339. #else
  340. #define DEFAULT_WASM_STACK_SIZE (12 * 1024)
  341. #endif
  342. /* Min auxiliary stack size of each wasm thread */
  343. #define WASM_THREAD_AUX_STACK_SIZE_MIN (256)
  344. /* Default/min native stack size of each app thread */
  345. #if !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
  346. && defined(APP_THREAD_STACK_SIZE_MIN))
  347. #if defined(BH_PLATFORM_ZEPHYR) || defined(BH_PLATFORM_ALIOS_THINGS) \
  348. || defined(BH_PLATFORM_ESP_IDF) || defined(BH_PLATFORM_OPENRTOS)
  349. #define APP_THREAD_STACK_SIZE_DEFAULT (6 * 1024)
  350. #define APP_THREAD_STACK_SIZE_MIN (4 * 1024)
  351. #elif defined(PTHREAD_STACK_DEFAULT) && defined(PTHREAD_STACK_MIN)
  352. #define APP_THREAD_STACK_SIZE_DEFAULT PTHREAD_STACK_DEFAULT
  353. #define APP_THREAD_STACK_SIZE_MIN PTHREAD_STACK_MIN
  354. #elif WASM_ENABLE_UVWASI != 0
  355. /* UVWASI requires larger native stack */
  356. #define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
  357. #define APP_THREAD_STACK_SIZE_MIN (48 * 1024)
  358. #else
  359. #define APP_THREAD_STACK_SIZE_DEFAULT (128 * 1024)
  360. #define APP_THREAD_STACK_SIZE_MIN (24 * 1024)
  361. #endif
  362. #endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
  363. && defined(APP_THREAD_STACK_SIZE_MIN)) */
  364. /* Max native stack size of each app thread */
  365. #if !defined(APP_THREAD_STACK_SIZE_MAX)
  366. #define APP_THREAD_STACK_SIZE_MAX (8 * 1024 * 1024)
  367. #endif
  368. /* Reserved bytes to the native thread stack boundary, throw native
  369. * stack overflow exception if the guard boundary is reached
  370. *
  371. * WASM_STACK_GUARD_SIZE needs to be large enough for:
  372. *
  373. * - native functions
  374. *
  375. * w/o hw bound check, the overhead (aot_call_function etc) + the native
  376. * function itself. as of writing this, the former is about 1000 bytes
  377. * on macOS amd64.
  378. *
  379. * with hw bound check, theoretically, only needs to cover the logic to
  380. * set up the jmp_buf stack.
  381. *
  382. * - aot runtime functions
  383. * eg. aot_enlarge_memory.
  384. *
  385. * - w/o hw bound check, the interpreter loop
  386. *
  387. * the stack consumption heavily depends on compiler settings,
  388. * especially for huge functions like the classic interpreter's
  389. * wasm_interp_call_func_bytecode:
  390. *
  391. * 200 bytes (release build, macOS/amd64)
  392. * 2600 bytes (debug build, macOS/amd64)
  393. *
  394. * - platform-provided functions (eg. libc)
  395. *
  396. * the following are examples of the stack consumptions observed for
  397. * host APIs.
  398. *
  399. * snprintf: (used by eg. wasm_runtime_set_exception)
  400. * - about 1600 bytes on macOS/amd64
  401. * - about 2000 bytes on Ubuntu amd64 20.04
  402. *
  403. * gethostbyname:
  404. * - 3KB-6KB on macOS/amd64
  405. * - 10KB on Ubuntu amd64 20.04
  406. *
  407. * getaddrinfo:
  408. * - 4KB-17KB on macOS/amd64
  409. * - 12KB on Ubuntu amd64 20.04
  410. * - 0.3-1.5KB on NuttX/esp32s3
  411. *
  412. * - stack check wrapper functions generated by the aot compiler
  413. * (--stack-bounds-checks=1)
  414. *
  415. * wamrc issues a warning
  416. * "precheck functions themselves consume relatively large amount of stack"
  417. * when it detects wrapper functions requiring more than 1KB.
  418. *
  419. * - the ABI-defined red zone. eg. 128 bytes for SYSV x86-64 ABI.
  420. * cf. https://en.wikipedia.org/wiki/Red_zone_(computing)
  421. *
  422. * Note: on platforms with lazy function binding, don't forget to consider
  423. * the symbol resolution overhead on the first call. For example,
  424. * on Ubuntu amd64 20.04, it seems to consume about 1500 bytes.
  425. * For some reasons, macOS amd64 12.7.4 seems to resolve symbols eagerly.
  426. * (Observed with a binary with traditional non-chained fixups.)
  427. * The latest macOS seems to apply chained fixups in kernel on page-in time.
  428. * (thus it wouldn't consume userland stack.)
  429. */
  430. #ifndef WASM_STACK_GUARD_SIZE
  431. #if WASM_ENABLE_UVWASI != 0
  432. /* UVWASI requires larger native stack */
  433. #define WASM_STACK_GUARD_SIZE (4096 * 6)
  434. #else
  435. /*
  436. * Use a larger default for platforms like macOS/Linux.
  437. *
  438. * For example, the classic interpreter loop which ended up with a trap
  439. * (wasm_runtime_set_exception) would consume about 2KB stack on x86-64
  440. * macOS. On Ubuntu amd64 20.04, it seems to consume a bit more.
  441. *
  442. * Although product-mini/platforms/nuttx always overrides
  443. * WASM_STACK_GUARD_SIZE, exclude NuttX here just in case.
  444. */
  445. #if defined(__APPLE__) || (defined(__unix__) && !defined(__NuttX__))
  446. #if BH_DEBUG != 0 /* assumption: BH_DEBUG matches CMAKE_BUILD_TYPE=Debug */
  447. #define WASM_STACK_GUARD_SIZE (1024 * 5)
  448. #else
  449. #define WASM_STACK_GUARD_SIZE (1024 * 3)
  450. #endif
  451. #else
  452. /*
  453. * Otherwise, assume very small requirement for now.
  454. *
  455. * Embedders for very small devices likely fine-tune WASM_STACK_GUARD_SIZE
  456. * for their specific applications anyway.
  457. */
  458. #define WASM_STACK_GUARD_SIZE 1024
  459. #endif
  460. #endif
  461. #endif
  462. /* Guard page count for stack overflow check with hardware trap */
  463. #ifndef STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT
  464. #if defined(__APPLE__) && defined(__aarch64__)
  465. /* Note: on macOS/iOS arm64, the user page size is 16KB */
  466. #define STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT 1
  467. #else
  468. #define STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT 3
  469. #endif
  470. #endif
  471. /* Default wasm block address cache size and conflict list size */
  472. #ifndef BLOCK_ADDR_CACHE_SIZE
  473. #define BLOCK_ADDR_CACHE_SIZE 64
  474. #endif
  475. #define BLOCK_ADDR_CONFLICT_SIZE 2
  476. /* Default max thread num per cluster. Can be overwrite by
  477. wasm_runtime_set_max_thread_num */
  478. #define CLUSTER_MAX_THREAD_NUM 4
  479. #ifndef WASM_ENABLE_TAIL_CALL
  480. #define WASM_ENABLE_TAIL_CALL 0
  481. #endif
  482. #ifndef WASM_ENABLE_CUSTOM_NAME_SECTION
  483. #define WASM_ENABLE_CUSTOM_NAME_SECTION 0
  484. #endif
  485. #ifndef WASM_ENABLE_REF_TYPES
  486. #define WASM_ENABLE_REF_TYPES 0
  487. #endif
  488. #ifndef WASM_ENABLE_GC
  489. #define WASM_ENABLE_GC 0
  490. #endif
  491. #ifndef WASM_CONST_EXPR_STACK_SIZE
  492. #if WASM_ENABLE_GC != 0
  493. #define WASM_CONST_EXPR_STACK_SIZE 8
  494. #else
  495. #define WASM_CONST_EXPR_STACK_SIZE 4
  496. #endif
  497. #endif
  498. #ifndef WASM_ENABLE_STRINGREF
  499. #define WASM_ENABLE_STRINGREF 0
  500. #endif
  501. #ifndef GC_REFTYPE_MAP_SIZE_DEFAULT
  502. #define GC_REFTYPE_MAP_SIZE_DEFAULT 64
  503. #endif
  504. #ifndef GC_RTTOBJ_MAP_SIZE_DEFAULT
  505. #define GC_RTTOBJ_MAP_SIZE_DEFAULT 64
  506. #endif
  507. #ifndef WASM_ENABLE_EXCE_HANDLING
  508. #define WASM_ENABLE_EXCE_HANDLING 0
  509. #endif
  510. #ifndef WASM_ENABLE_TAGS
  511. #define WASM_ENABLE_TAGS 0
  512. #endif
  513. #ifndef WASM_ENABLE_SGX_IPFS
  514. #define WASM_ENABLE_SGX_IPFS 0
  515. #endif
  516. #ifndef WASM_MEM_ALLOC_WITH_USER_DATA
  517. #define WASM_MEM_ALLOC_WITH_USER_DATA 0
  518. #endif
  519. #ifndef WASM_ENABLE_WASM_CACHE
  520. #define WASM_ENABLE_WASM_CACHE 0
  521. #endif
  522. #ifndef WASM_ENABLE_STATIC_PGO
  523. #define WASM_ENABLE_STATIC_PGO 0
  524. #endif
  525. /* Disable writing linear memory base address to GS segment register,
  526. by default only in linux x86-64, linear memory base addr is written
  527. to GS segment register before calling wasm/aot function. */
  528. #ifndef WASM_DISABLE_WRITE_GS_BASE
  529. #define WASM_DISABLE_WRITE_GS_BASE 0
  530. #endif
  531. /* Configurable bounds checks */
  532. #ifndef WASM_CONFIGURABLE_BOUNDS_CHECKS
  533. #define WASM_CONFIGURABLE_BOUNDS_CHECKS 0
  534. #endif
  535. /* Some chip cannot support external ram with rwx attr at the same time,
  536. it has to map it into 2 spaces of idbus and dbus, code in dbus can be
  537. read/written and read/executed in ibus. so there are 2 steps to execute
  538. the code, first, copy & do relocation in dbus space, and second execute
  539. it in ibus space, since in the 2 spaces the contents are the same,
  540. so we call it bus mirror.
  541. */
  542. #ifndef WASM_MEM_DUAL_BUS_MIRROR
  543. #define WASM_MEM_DUAL_BUS_MIRROR 0
  544. #endif
  545. /* The max number of module instance contexts. */
  546. #ifndef WASM_MAX_INSTANCE_CONTEXTS
  547. #define WASM_MAX_INSTANCE_CONTEXTS 8
  548. #endif
  549. /* linux perf support */
  550. #ifndef WASM_ENABLE_LINUX_PERF
  551. #define WASM_ENABLE_LINUX_PERF 0
  552. #endif
  553. /* Support registering quick AOT/JIT function entries of some func types
  554. to speed up the calling process of invoking the AOT/JIT functions of
  555. these types from the host embedder */
  556. #ifndef WASM_ENABLE_QUICK_AOT_ENTRY
  557. #define WASM_ENABLE_QUICK_AOT_ENTRY 1
  558. #endif
  559. /* Support AOT intrinsic functions which can be called from the AOT code
  560. when `--disable-llvm-intrinsics` flag or
  561. `--enable-builtin-intrinsics=<intr1,intr2,...>` is used by wamrc to
  562. generate the AOT file */
  563. #ifndef WASM_ENABLE_AOT_INTRINSICS
  564. #define WASM_ENABLE_AOT_INTRINSICS 1
  565. #endif
  566. /* Disable memory64 by default */
  567. #ifndef WASM_ENABLE_MEMORY64
  568. #define WASM_ENABLE_MEMORY64 0
  569. #endif
  570. /* Disable multi-memory by default */
  571. #ifndef WASM_ENABLE_MULTI_MEMORY
  572. #define WASM_ENABLE_MULTI_MEMORY 0
  573. #endif
  574. #ifndef WASM_TABLE_MAX_SIZE
  575. #define WASM_TABLE_MAX_SIZE 1024
  576. #endif
  577. #ifndef WASM_MEM_ALLOC_WITH_USAGE
  578. #define WASM_MEM_ALLOC_WITH_USAGE 0
  579. #endif
  580. #ifndef WASM_ENABLE_FUZZ_TEST
  581. #define WASM_ENABLE_FUZZ_TEST 0
  582. #endif
  583. #if WASM_ENABLE_FUZZ_TEST != 0
  584. #ifndef WASM_MEM_ALLOC_MAX_SIZE
  585. /* In oss-fuzz, the maximum RAM is ~2.5G */
  586. #define WASM_MEM_ALLOC_MAX_SIZE (2U * 1024 * 1024 * 1024)
  587. #endif
  588. #endif /* WASM_ENABLE_FUZZ_TEST != 0 */
  589. #ifndef WASM_ENABLE_SHARED_HEAP
  590. #define WASM_ENABLE_SHARED_HEAP 0
  591. #endif
  592. #ifndef WASM_ENABLE_SHRUNK_MEMORY
  593. #define WASM_ENABLE_SHRUNK_MEMORY 1
  594. #endif
  595. #ifndef WASM_ENABLE_AOT_VALIDATOR
  596. #define WASM_ENABLE_AOT_VALIDATOR 0
  597. #endif
  598. #endif /* end of _CONFIG_H_ */