config.h 19 KB

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