config.h 18 KB

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