@shd101wyy/yo 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +80 -0
  3. package/out/cjs/index.cjs +51 -0
  4. package/out/cjs/yo-cli.cjs +2158 -0
  5. package/out/esm/index.mjs +51 -0
  6. package/out/types/src/codegen/async/runtime.d.ts +2 -0
  7. package/out/types/src/codegen/async/state-code-gen.d.ts +10 -0
  8. package/out/types/src/codegen/async/state-machine.d.ts +13 -0
  9. package/out/types/src/codegen/c/collection.d.ts +3 -0
  10. package/out/types/src/codegen/codegen-c.d.ts +12 -0
  11. package/out/types/src/codegen/constants.d.ts +3 -0
  12. package/out/types/src/codegen/expressions/array.d.ts +4 -0
  13. package/out/types/src/codegen/expressions/generation.d.ts +11 -0
  14. package/out/types/src/codegen/expressions/index.d.ts +2 -0
  15. package/out/types/src/codegen/functions/collection.d.ts +5 -0
  16. package/out/types/src/codegen/functions/context.d.ts +57 -0
  17. package/out/types/src/codegen/functions/generation.d.ts +25 -0
  18. package/out/types/src/codegen/functions/index.d.ts +2 -0
  19. package/out/types/src/codegen/index.d.ts +20 -0
  20. package/out/types/src/codegen/parallelism/runtime.d.ts +2 -0
  21. package/out/types/src/codegen/types/collection.d.ts +8 -0
  22. package/out/types/src/codegen/types/generation.d.ts +13 -0
  23. package/out/types/src/codegen/types/index.d.ts +2 -0
  24. package/out/types/src/codegen/utils/fixup.d.ts +2 -0
  25. package/out/types/src/codegen/utils/index.d.ts +77 -0
  26. package/out/types/src/codegen/values/index.d.ts +1 -0
  27. package/out/types/src/emitter.d.ts +11 -0
  28. package/out/types/src/env.d.ts +85 -0
  29. package/out/types/src/error.d.ts +45 -0
  30. package/out/types/src/evaluator/async/await-analysis-types.d.ts +23 -0
  31. package/out/types/src/evaluator/async/await-analysis.d.ts +5 -0
  32. package/out/types/src/evaluator/builtins/alignof.d.ts +8 -0
  33. package/out/types/src/evaluator/builtins/and_or.d.ts +8 -0
  34. package/out/types/src/evaluator/builtins/arc_fns.d.ts +58 -0
  35. package/out/types/src/evaluator/builtins/array_fns.d.ts +0 -0
  36. package/out/types/src/evaluator/builtins/as.d.ts +8 -0
  37. package/out/types/src/evaluator/builtins/async_fns.d.ts +8 -0
  38. package/out/types/src/evaluator/builtins/compt_assert.d.ts +8 -0
  39. package/out/types/src/evaluator/builtins/compt_boolean_fns.d.ts +8 -0
  40. package/out/types/src/evaluator/builtins/compt_expect_error.d.ts +8 -0
  41. package/out/types/src/evaluator/builtins/compt_list_fns.d.ts +33 -0
  42. package/out/types/src/evaluator/builtins/compt_print.d.ts +8 -0
  43. package/out/types/src/evaluator/builtins/compt_string_fns.d.ts +8 -0
  44. package/out/types/src/evaluator/builtins/consume.d.ts +8 -0
  45. package/out/types/src/evaluator/builtins/drop.d.ts +8 -0
  46. package/out/types/src/evaluator/builtins/dup.d.ts +8 -0
  47. package/out/types/src/evaluator/builtins/expr_fns.d.ts +33 -0
  48. package/out/types/src/evaluator/builtins/future_fns.d.ts +8 -0
  49. package/out/types/src/evaluator/builtins/gc.d.ts +8 -0
  50. package/out/types/src/evaluator/builtins/gensym.d.ts +8 -0
  51. package/out/types/src/evaluator/builtins/impl_constraint.d.ts +8 -0
  52. package/out/types/src/evaluator/builtins/macro_expand.d.ts +8 -0
  53. package/out/types/src/evaluator/builtins/numeric_fns.d.ts +8 -0
  54. package/out/types/src/evaluator/builtins/panic.d.ts +8 -0
  55. package/out/types/src/evaluator/builtins/ptr_fns.d.ts +8 -0
  56. package/out/types/src/evaluator/builtins/quote.d.ts +13 -0
  57. package/out/types/src/evaluator/builtins/rc.d.ts +8 -0
  58. package/out/types/src/evaluator/builtins/sizeof.d.ts +8 -0
  59. package/out/types/src/evaluator/builtins/the.d.ts +8 -0
  60. package/out/types/src/evaluator/builtins/type_fns.d.ts +28 -0
  61. package/out/types/src/evaluator/builtins/va_start.d.ts +8 -0
  62. package/out/types/src/evaluator/builtins/var_fns.d.ts +18 -0
  63. package/out/types/src/evaluator/calls/array.d.ts +13 -0
  64. package/out/types/src/evaluator/calls/array_type.d.ts +11 -0
  65. package/out/types/src/evaluator/calls/closure_type.d.ts +11 -0
  66. package/out/types/src/evaluator/calls/compt_function.d.ts +19 -0
  67. package/out/types/src/evaluator/calls/compt_list_type.d.ts +11 -0
  68. package/out/types/src/evaluator/calls/function.d.ts +16 -0
  69. package/out/types/src/evaluator/calls/function_type.d.ts +15 -0
  70. package/out/types/src/evaluator/calls/helper.d.ts +42 -0
  71. package/out/types/src/evaluator/calls/iso.d.ts +15 -0
  72. package/out/types/src/evaluator/calls/module_type.d.ts +11 -0
  73. package/out/types/src/evaluator/calls/numeric_type.d.ts +15 -0
  74. package/out/types/src/evaluator/calls/pointer.d.ts +8 -0
  75. package/out/types/src/evaluator/calls/pointer_type.d.ts +14 -0
  76. package/out/types/src/evaluator/calls/type.d.ts +12 -0
  77. package/out/types/src/evaluator/context.d.ts +169 -0
  78. package/out/types/src/evaluator/exprs/_expr.d.ts +8 -0
  79. package/out/types/src/evaluator/exprs/assignment.d.ts +9 -0
  80. package/out/types/src/evaluator/exprs/begin.d.ts +10 -0
  81. package/out/types/src/evaluator/exprs/binding.d.ts +12 -0
  82. package/out/types/src/evaluator/exprs/c_include.d.ts +8 -0
  83. package/out/types/src/evaluator/exprs/cond.d.ts +8 -0
  84. package/out/types/src/evaluator/exprs/destructuring_assignment.d.ts +33 -0
  85. package/out/types/src/evaluator/exprs/exists.d.ts +0 -0
  86. package/out/types/src/evaluator/exprs/expr.d.ts +9 -0
  87. package/out/types/src/evaluator/exprs/extern.d.ts +8 -0
  88. package/out/types/src/evaluator/exprs/identifer_and_operator.d.ts +9 -0
  89. package/out/types/src/evaluator/exprs/import.d.ts +9 -0
  90. package/out/types/src/evaluator/exprs/initialization_assignment.d.ts +8 -0
  91. package/out/types/src/evaluator/exprs/match.d.ts +8 -0
  92. package/out/types/src/evaluator/exprs/open.d.ts +8 -0
  93. package/out/types/src/evaluator/exprs/property_access.d.ts +8 -0
  94. package/out/types/src/evaluator/exprs/recur.d.ts +8 -0
  95. package/out/types/src/evaluator/exprs/subtype_of.d.ts +21 -0
  96. package/out/types/src/evaluator/exprs/test.d.ts +8 -0
  97. package/out/types/src/evaluator/exprs/typeof.d.ts +8 -0
  98. package/out/types/src/evaluator/exprs/while.d.ts +8 -0
  99. package/out/types/src/evaluator/index.d.ts +26 -0
  100. package/out/types/src/evaluator/types/array.d.ts +8 -0
  101. package/out/types/src/evaluator/types/closure.d.ts +8 -0
  102. package/out/types/src/evaluator/types/compt_list.d.ts +8 -0
  103. package/out/types/src/evaluator/types/concrete_module.d.ts +8 -0
  104. package/out/types/src/evaluator/types/dyn.d.ts +8 -0
  105. package/out/types/src/evaluator/types/enum.d.ts +8 -0
  106. package/out/types/src/evaluator/types/expr_synthesizer.d.ts +14 -0
  107. package/out/types/src/evaluator/types/field.d.ts +14 -0
  108. package/out/types/src/evaluator/types/fn_module.d.ts +8 -0
  109. package/out/types/src/evaluator/types/function.d.ts +58 -0
  110. package/out/types/src/evaluator/types/future_module.d.ts +8 -0
  111. package/out/types/src/evaluator/types/module.d.ts +19 -0
  112. package/out/types/src/evaluator/types/newtype.d.ts +8 -0
  113. package/out/types/src/evaluator/types/object.d.ts +8 -0
  114. package/out/types/src/evaluator/types/proofs.d.ts +0 -0
  115. package/out/types/src/evaluator/types/slice.d.ts +8 -0
  116. package/out/types/src/evaluator/types/struct.d.ts +8 -0
  117. package/out/types/src/evaluator/types/synthesizer.d.ts +16 -0
  118. package/out/types/src/evaluator/types/tuple.d.ts +18 -0
  119. package/out/types/src/evaluator/types/union.d.ts +8 -0
  120. package/out/types/src/evaluator/types/utils.d.ts +71 -0
  121. package/out/types/src/evaluator/types/validation.d.ts +3 -0
  122. package/out/types/src/evaluator/utils/array-utils.d.ts +15 -0
  123. package/out/types/src/evaluator/utils/closure.d.ts +35 -0
  124. package/out/types/src/evaluator/utils.d.ts +4 -0
  125. package/out/types/src/evaluator/values/anonymous_function.d.ts +8 -0
  126. package/out/types/src/evaluator/values/anonymous_module.d.ts +17 -0
  127. package/out/types/src/evaluator/values/anonymous_struct.d.ts +8 -0
  128. package/out/types/src/evaluator/values/array.d.ts +8 -0
  129. package/out/types/src/evaluator/values/boolean.d.ts +3 -0
  130. package/out/types/src/evaluator/values/char.d.ts +3 -0
  131. package/out/types/src/evaluator/values/compt_list.d.ts +8 -0
  132. package/out/types/src/evaluator/values/dyn.d.ts +8 -0
  133. package/out/types/src/evaluator/values/float.d.ts +4 -0
  134. package/out/types/src/evaluator/values/integer.d.ts +4 -0
  135. package/out/types/src/evaluator/values/module.d.ts +58 -0
  136. package/out/types/src/evaluator/values/string.d.ts +3 -0
  137. package/out/types/src/evaluator/values/tuple.d.ts +32 -0
  138. package/out/types/src/expr.d.ts +456 -0
  139. package/out/types/src/function-value.d.ts +42 -0
  140. package/out/types/src/index.d.ts +4 -0
  141. package/out/types/src/lexer.d.ts +2 -0
  142. package/out/types/src/logger.d.ts +1 -0
  143. package/out/types/src/module-manager.d.ts +30 -0
  144. package/out/types/src/naming-checker.d.ts +4 -0
  145. package/out/types/src/parser.d.ts +33 -0
  146. package/out/types/src/test-runner.d.ts +30 -0
  147. package/out/types/src/tests/codegen.test.d.ts +1 -0
  148. package/out/types/src/tests/fixme.test.d.ts +1 -0
  149. package/out/types/src/tests/module-manager.test.d.ts +1 -0
  150. package/out/types/src/tests/parser.test.d.ts +1 -0
  151. package/out/types/src/tests/sample.test.d.ts +0 -0
  152. package/out/types/src/tests/std.test.d.ts +1 -0
  153. package/out/types/src/token.d.ts +40 -0
  154. package/out/types/src/type-value.d.ts +7 -0
  155. package/out/types/src/types/compatibility.d.ts +16 -0
  156. package/out/types/src/types/creators.d.ts +73 -0
  157. package/out/types/src/types/definitions.d.ts +218 -0
  158. package/out/types/src/types/guards.d.ts +70 -0
  159. package/out/types/src/types/hierarchy.d.ts +4 -0
  160. package/out/types/src/types/index.d.ts +7 -0
  161. package/out/types/src/types/module_field.d.ts +2 -0
  162. package/out/types/src/types/tags.d.ts +45 -0
  163. package/out/types/src/types/utils.d.ts +50 -0
  164. package/out/types/src/unit-value.d.ts +7 -0
  165. package/out/types/src/utils.d.ts +6 -0
  166. package/out/types/src/value-tag.d.ts +29 -0
  167. package/out/types/src/value.d.ts +110 -0
  168. package/out/types/src/yo-cli.d.ts +1 -0
  169. package/out/types/tsconfig.tsbuildinfo +1 -0
  170. package/package.json +57 -0
  171. package/scripts/check-liburing.js +76 -0
  172. package/std/alg/hash.yo +50 -0
  173. package/std/allocator.yo +113 -0
  174. package/std/allocators/c_allocator.yo +118 -0
  175. package/std/async.yo +13 -0
  176. package/std/collections/array_list.yo +415 -0
  177. package/std/collections/hash_map.yo +482 -0
  178. package/std/collections/hash_set.yo +706 -0
  179. package/std/collections/index.yo +11 -0
  180. package/std/collections/linked_list.yo +439 -0
  181. package/std/error.yo +0 -0
  182. package/std/gc.yo +10 -0
  183. package/std/index.yo +12 -0
  184. package/std/io/file.yo +191 -0
  185. package/std/io/index.yo +5 -0
  186. package/std/libc/assert.yo +39 -0
  187. package/std/libc/ctype.yo +57 -0
  188. package/std/libc/errno.yo +182 -0
  189. package/std/libc/float.yo +87 -0
  190. package/std/libc/index.yo +29 -0
  191. package/std/libc/limits.yo +65 -0
  192. package/std/libc/math.yo +679 -0
  193. package/std/libc/signal.yo +101 -0
  194. package/std/libc/stdatomic.yo +213 -0
  195. package/std/libc/stdint.yo +214 -0
  196. package/std/libc/stdio.yo +225 -0
  197. package/std/libc/stdlib.yo +204 -0
  198. package/std/libc/string.yo +151 -0
  199. package/std/libc/time.yo +92 -0
  200. package/std/libc/unistd.yo +130 -0
  201. package/std/monad.yo +152 -0
  202. package/std/prelude.yo +3094 -0
  203. package/std/string/index.yo +8 -0
  204. package/std/string/rune.yo +82 -0
  205. package/std/string/string.yo +288 -0
  206. package/std/sync.yo +95 -0
  207. package/std/thread.yo +36 -0
  208. package/std/time.yo +13 -0
  209. package/std/worker.yo +36 -0
  210. package/vendor/mimalloc/.gitattributes +12 -0
  211. package/vendor/mimalloc/CMakeLists.txt +763 -0
  212. package/vendor/mimalloc/LICENSE +21 -0
  213. package/vendor/mimalloc/SECURITY.md +41 -0
  214. package/vendor/mimalloc/azure-pipelines.yml +251 -0
  215. package/vendor/mimalloc/bin/mimalloc-redirect-arm64.dll +0 -0
  216. package/vendor/mimalloc/bin/mimalloc-redirect-arm64.lib +0 -0
  217. package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.dll +0 -0
  218. package/vendor/mimalloc/bin/mimalloc-redirect-arm64ec.lib +0 -0
  219. package/vendor/mimalloc/bin/mimalloc-redirect.dll +0 -0
  220. package/vendor/mimalloc/bin/mimalloc-redirect.lib +0 -0
  221. package/vendor/mimalloc/bin/mimalloc-redirect32.dll +0 -0
  222. package/vendor/mimalloc/bin/mimalloc-redirect32.lib +0 -0
  223. package/vendor/mimalloc/bin/minject-arm64.exe +0 -0
  224. package/vendor/mimalloc/bin/minject.exe +0 -0
  225. package/vendor/mimalloc/bin/minject32.exe +0 -0
  226. package/vendor/mimalloc/bin/readme.md +118 -0
  227. package/vendor/mimalloc/cmake/JoinPaths.cmake +23 -0
  228. package/vendor/mimalloc/cmake/mimalloc-config-version.cmake +19 -0
  229. package/vendor/mimalloc/cmake/mimalloc-config.cmake +14 -0
  230. package/vendor/mimalloc/contrib/docker/alpine/Dockerfile +23 -0
  231. package/vendor/mimalloc/contrib/docker/alpine-arm32v7/Dockerfile +28 -0
  232. package/vendor/mimalloc/contrib/docker/alpine-x86/Dockerfile +28 -0
  233. package/vendor/mimalloc/contrib/docker/manylinux-x64/Dockerfile +23 -0
  234. package/vendor/mimalloc/contrib/docker/readme.md +10 -0
  235. package/vendor/mimalloc/contrib/vcpkg/portfile.cmake +64 -0
  236. package/vendor/mimalloc/contrib/vcpkg/readme.md +40 -0
  237. package/vendor/mimalloc/contrib/vcpkg/usage +20 -0
  238. package/vendor/mimalloc/contrib/vcpkg/vcpkg-cmake-wrapper.cmake +20 -0
  239. package/vendor/mimalloc/contrib/vcpkg/vcpkg.json +48 -0
  240. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-a.svg +887 -0
  241. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-b.svg +1185 -0
  242. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-a.svg +757 -0
  243. package/vendor/mimalloc/doc/bench-2020/bench-c5-18xlarge-2020-01-20-rss-b.svg +1028 -0
  244. package/vendor/mimalloc/doc/bench-2020/bench-r5a-1.svg +769 -0
  245. package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-a.svg +868 -0
  246. package/vendor/mimalloc/doc/bench-2020/bench-r5a-12xlarge-2020-01-16-b.svg +1157 -0
  247. package/vendor/mimalloc/doc/bench-2020/bench-r5a-2.svg +983 -0
  248. package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-1.svg +683 -0
  249. package/vendor/mimalloc/doc/bench-2020/bench-r5a-rss-2.svg +854 -0
  250. package/vendor/mimalloc/doc/bench-2020/bench-spec-rss.svg +713 -0
  251. package/vendor/mimalloc/doc/bench-2020/bench-spec.svg +713 -0
  252. package/vendor/mimalloc/doc/bench-2020/bench-z4-1.svg +890 -0
  253. package/vendor/mimalloc/doc/bench-2020/bench-z4-2.svg +1146 -0
  254. package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-1.svg +796 -0
  255. package/vendor/mimalloc/doc/bench-2020/bench-z4-rss-2.svg +974 -0
  256. package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-a.svg +952 -0
  257. package/vendor/mimalloc/doc/bench-2021/bench-amd5950x-2021-01-30-b.svg +1255 -0
  258. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-a.svg +955 -0
  259. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-b.svg +1269 -0
  260. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-a.svg +836 -0
  261. package/vendor/mimalloc/doc/bench-2021/bench-c5-18xlarge-2021-01-30-rss-b.svg +1131 -0
  262. package/vendor/mimalloc/doc/bench-2021/bench-macmini-2021-01-30.svg +766 -0
  263. package/vendor/mimalloc/doc/doxyfile +2895 -0
  264. package/vendor/mimalloc/doc/ds-logo.jpg +0 -0
  265. package/vendor/mimalloc/doc/ds-logo.png +0 -0
  266. package/vendor/mimalloc/doc/mimalloc-doc.h +1452 -0
  267. package/vendor/mimalloc/doc/mimalloc-doxygen.css +60 -0
  268. package/vendor/mimalloc/doc/mimalloc-logo-100.png +0 -0
  269. package/vendor/mimalloc/doc/mimalloc-logo.png +0 -0
  270. package/vendor/mimalloc/doc/mimalloc-logo.svg +161 -0
  271. package/vendor/mimalloc/doc/spades-logo.png +0 -0
  272. package/vendor/mimalloc/doc/unreal-logo.svg +43 -0
  273. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj +500 -0
  274. package/vendor/mimalloc/ide/vs2022/mimalloc-lib.vcxproj.filters +108 -0
  275. package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj +508 -0
  276. package/vendor/mimalloc/ide/vs2022/mimalloc-override-dll.vcxproj.filters +111 -0
  277. package/vendor/mimalloc/ide/vs2022/mimalloc-override-test-dep.vcxproj +355 -0
  278. package/vendor/mimalloc/ide/vs2022/mimalloc-override-test.vcxproj +360 -0
  279. package/vendor/mimalloc/ide/vs2022/mimalloc-test-api.vcxproj +295 -0
  280. package/vendor/mimalloc/ide/vs2022/mimalloc-test-stress.vcxproj +292 -0
  281. package/vendor/mimalloc/ide/vs2022/mimalloc-test.vcxproj +289 -0
  282. package/vendor/mimalloc/ide/vs2022/mimalloc.sln +151 -0
  283. package/vendor/mimalloc/include/mimalloc/atomic.h +557 -0
  284. package/vendor/mimalloc/include/mimalloc/internal.h +1153 -0
  285. package/vendor/mimalloc/include/mimalloc/prim.h +421 -0
  286. package/vendor/mimalloc/include/mimalloc/track.h +145 -0
  287. package/vendor/mimalloc/include/mimalloc/types.h +685 -0
  288. package/vendor/mimalloc/include/mimalloc-new-delete.h +66 -0
  289. package/vendor/mimalloc/include/mimalloc-override.h +68 -0
  290. package/vendor/mimalloc/include/mimalloc-stats.h +103 -0
  291. package/vendor/mimalloc/include/mimalloc.h +612 -0
  292. package/vendor/mimalloc/mimalloc.pc.in +11 -0
  293. package/vendor/mimalloc/readme.md +946 -0
  294. package/vendor/mimalloc/src/alloc-aligned.c +360 -0
  295. package/vendor/mimalloc/src/alloc-override.c +316 -0
  296. package/vendor/mimalloc/src/alloc-posix.c +185 -0
  297. package/vendor/mimalloc/src/alloc.c +692 -0
  298. package/vendor/mimalloc/src/arena-abandon.c +346 -0
  299. package/vendor/mimalloc/src/arena.c +1043 -0
  300. package/vendor/mimalloc/src/bitmap.c +441 -0
  301. package/vendor/mimalloc/src/bitmap.h +119 -0
  302. package/vendor/mimalloc/src/free.c +572 -0
  303. package/vendor/mimalloc/src/heap.c +733 -0
  304. package/vendor/mimalloc/src/init.c +714 -0
  305. package/vendor/mimalloc/src/libc.c +334 -0
  306. package/vendor/mimalloc/src/options.c +663 -0
  307. package/vendor/mimalloc/src/os.c +770 -0
  308. package/vendor/mimalloc/src/page-queue.c +390 -0
  309. package/vendor/mimalloc/src/page.c +1049 -0
  310. package/vendor/mimalloc/src/prim/emscripten/prim.c +249 -0
  311. package/vendor/mimalloc/src/prim/osx/alloc-override-zone.c +461 -0
  312. package/vendor/mimalloc/src/prim/osx/prim.c +9 -0
  313. package/vendor/mimalloc/src/prim/prim.c +76 -0
  314. package/vendor/mimalloc/src/prim/readme.md +9 -0
  315. package/vendor/mimalloc/src/prim/unix/prim.c +934 -0
  316. package/vendor/mimalloc/src/prim/wasi/prim.c +284 -0
  317. package/vendor/mimalloc/src/prim/windows/etw-mimalloc.wprp +61 -0
  318. package/vendor/mimalloc/src/prim/windows/etw.h +905 -0
  319. package/vendor/mimalloc/src/prim/windows/etw.man +0 -0
  320. package/vendor/mimalloc/src/prim/windows/prim.c +878 -0
  321. package/vendor/mimalloc/src/prim/windows/readme.md +17 -0
  322. package/vendor/mimalloc/src/random.c +258 -0
  323. package/vendor/mimalloc/src/segment-map.c +142 -0
  324. package/vendor/mimalloc/src/segment.c +1702 -0
  325. package/vendor/mimalloc/src/static.c +41 -0
  326. package/vendor/mimalloc/src/stats.c +635 -0
  327. package/vendor/mimalloc/test/CMakeLists.txt +56 -0
  328. package/vendor/mimalloc/test/main-override-dep.cpp +51 -0
  329. package/vendor/mimalloc/test/main-override-dep.h +11 -0
  330. package/vendor/mimalloc/test/main-override-static.c +539 -0
  331. package/vendor/mimalloc/test/main-override.c +36 -0
  332. package/vendor/mimalloc/test/main-override.cpp +497 -0
  333. package/vendor/mimalloc/test/main.c +46 -0
  334. package/vendor/mimalloc/test/readme.md +16 -0
  335. package/vendor/mimalloc/test/test-api-fill.c +343 -0
  336. package/vendor/mimalloc/test/test-api.c +466 -0
  337. package/vendor/mimalloc/test/test-stress.c +428 -0
  338. package/vendor/mimalloc/test/test-wrong.c +92 -0
  339. package/vendor/mimalloc/test/testhelper.h +49 -0
@@ -0,0 +1,421 @@
1
+ /* ----------------------------------------------------------------------------
2
+ Copyright (c) 2018-2024, Microsoft Research, Daan Leijen
3
+ This is free software; you can redistribute it and/or modify it under the
4
+ terms of the MIT license. A copy of the license can be found in the file
5
+ "LICENSE" at the root of this distribution.
6
+ -----------------------------------------------------------------------------*/
7
+ #pragma once
8
+ #ifndef MIMALLOC_PRIM_H
9
+ #define MIMALLOC_PRIM_H
10
+
11
+
12
+ // --------------------------------------------------------------------------
13
+ // This file specifies the primitive portability API.
14
+ // Each OS/host needs to implement these primitives, see `src/prim`
15
+ // for implementations on Window, macOS, WASI, and Linux/Unix.
16
+ //
17
+ // note: on all primitive functions, we always have result parameters != NULL, and:
18
+ // addr != NULL and page aligned
19
+ // size > 0 and page aligned
20
+ // the return value is an error code as an `int` where 0 is success
21
+ // --------------------------------------------------------------------------
22
+
23
+ // OS memory configuration
24
+ typedef struct mi_os_mem_config_s {
25
+ size_t page_size; // default to 4KiB
26
+ size_t large_page_size; // 0 if not supported, usually 2MiB (4MiB on Windows)
27
+ size_t alloc_granularity; // smallest allocation size (usually 4KiB, on Windows 64KiB)
28
+ size_t physical_memory_in_kib; // physical memory size in KiB
29
+ size_t virtual_address_bits; // usually 48 or 56 bits on 64-bit systems. (used to determine secure randomization)
30
+ bool has_overcommit; // can we reserve more memory than can be actually committed?
31
+ bool has_partial_free; // can allocated blocks be freed partially? (true for mmap, false for VirtualAlloc)
32
+ bool has_virtual_reserve; // supports virtual address space reservation? (if true we can reserve virtual address space without using commit or physical memory)
33
+ } mi_os_mem_config_t;
34
+
35
+ // Initialize
36
+ void _mi_prim_mem_init( mi_os_mem_config_t* config );
37
+
38
+ // Free OS memory
39
+ int _mi_prim_free(void* addr, size_t size );
40
+
41
+ // Allocate OS memory. Return NULL on error.
42
+ // The `try_alignment` is just a hint and the returned pointer does not have to be aligned.
43
+ // If `commit` is false, the virtual memory range only needs to be reserved (with no access)
44
+ // which will later be committed explicitly using `_mi_prim_commit`.
45
+ // `is_zero` is set to true if the memory was zero initialized (as on most OS's)
46
+ // The `hint_addr` address is either `NULL` or a preferred allocation address but can be ignored.
47
+ // pre: !commit => !allow_large
48
+ // try_alignment >= _mi_os_page_size() and a power of 2
49
+ int _mi_prim_alloc(void* hint_addr, size_t size, size_t try_alignment, bool commit, bool allow_large, bool* is_large, bool* is_zero, void** addr);
50
+
51
+ // Commit memory. Returns error code or 0 on success.
52
+ // For example, on Linux this would make the memory PROT_READ|PROT_WRITE.
53
+ // `is_zero` is set to true if the memory was zero initialized (e.g. on Windows)
54
+ int _mi_prim_commit(void* addr, size_t size, bool* is_zero);
55
+
56
+ // Decommit memory. Returns error code or 0 on success. The `needs_recommit` result is true
57
+ // if the memory would need to be re-committed. For example, on Windows this is always true,
58
+ // but on Linux we could use MADV_DONTNEED to decommit which does not need a recommit.
59
+ // pre: needs_recommit != NULL
60
+ int _mi_prim_decommit(void* addr, size_t size, bool* needs_recommit);
61
+
62
+ // Reset memory. The range keeps being accessible but the content might be reset to zero at any moment.
63
+ // Returns error code or 0 on success.
64
+ int _mi_prim_reset(void* addr, size_t size);
65
+
66
+ // Reuse memory. This is called for memory that is already committed but
67
+ // may have been reset (`_mi_prim_reset`) or decommitted (`_mi_prim_decommit`) where `needs_recommit` was false.
68
+ // Returns error code or 0 on success. On most platforms this is a no-op.
69
+ int _mi_prim_reuse(void* addr, size_t size);
70
+
71
+ // Protect memory. Returns error code or 0 on success.
72
+ int _mi_prim_protect(void* addr, size_t size, bool protect);
73
+
74
+ // Allocate huge (1GiB) pages possibly associated with a NUMA node.
75
+ // `is_zero` is set to true if the memory was zero initialized (as on most OS's)
76
+ // pre: size > 0 and a multiple of 1GiB.
77
+ // numa_node is either negative (don't care), or a numa node number.
78
+ int _mi_prim_alloc_huge_os_pages(void* hint_addr, size_t size, int numa_node, bool* is_zero, void** addr);
79
+
80
+ // Return the current NUMA node
81
+ size_t _mi_prim_numa_node(void);
82
+
83
+ // Return the number of logical NUMA nodes
84
+ size_t _mi_prim_numa_node_count(void);
85
+
86
+ // Clock ticks
87
+ mi_msecs_t _mi_prim_clock_now(void);
88
+
89
+ // Return process information (only for statistics)
90
+ typedef struct mi_process_info_s {
91
+ mi_msecs_t elapsed;
92
+ mi_msecs_t utime;
93
+ mi_msecs_t stime;
94
+ size_t current_rss;
95
+ size_t peak_rss;
96
+ size_t current_commit;
97
+ size_t peak_commit;
98
+ size_t page_faults;
99
+ } mi_process_info_t;
100
+
101
+ void _mi_prim_process_info(mi_process_info_t* pinfo);
102
+
103
+ // Default stderr output. (only for warnings etc. with verbose enabled)
104
+ // msg != NULL && _mi_strlen(msg) > 0
105
+ void _mi_prim_out_stderr( const char* msg );
106
+
107
+ // Get an environment variable. (only for options)
108
+ // name != NULL, result != NULL, result_size >= 64
109
+ bool _mi_prim_getenv(const char* name, char* result, size_t result_size);
110
+
111
+
112
+ // Fill a buffer with strong randomness; return `false` on error or if
113
+ // there is no strong randomization available.
114
+ bool _mi_prim_random_buf(void* buf, size_t buf_len);
115
+
116
+ // Called on the first thread start, and should ensure `_mi_thread_done` is called on thread termination.
117
+ void _mi_prim_thread_init_auto_done(void);
118
+
119
+ // Called on process exit and may take action to clean up resources associated with the thread auto done.
120
+ void _mi_prim_thread_done_auto_done(void);
121
+
122
+ // Called when the default heap for a thread changes
123
+ void _mi_prim_thread_associate_default_heap(mi_heap_t* heap);
124
+
125
+
126
+ //-------------------------------------------------------------------
127
+ // Access to TLS (thread local storage) slots.
128
+ // We need fast access to both a unique thread id (in `free.c:mi_free`) and
129
+ // to a thread-local heap pointer (in `alloc.c:mi_malloc`).
130
+ // To achieve this we use specialized code for various platforms.
131
+ //-------------------------------------------------------------------
132
+
133
+ // On some libc + platform combinations we can directly access a thread-local storage (TLS) slot.
134
+ // The TLS layout depends on both the OS and libc implementation so we use specific tests for each main platform.
135
+ // If you test on another platform and it works please send a PR :-)
136
+ // see also https://akkadia.org/drepper/tls.pdf for more info on the TLS register.
137
+ //
138
+ // Note: we would like to prefer `__builtin_thread_pointer()` nowadays instead of using assembly,
139
+ // but unfortunately we can not detect support reliably (see issue #883)
140
+ // We also use it on Apple OS as we use a TLS slot for the default heap there.
141
+ #if defined(__GNUC__) && ( \
142
+ (defined(__GLIBC__) && (defined(__x86_64__) || defined(__i386__) || (defined(__arm__) && __ARM_ARCH >= 7) || defined(__aarch64__))) \
143
+ || (defined(__APPLE__) && (defined(__x86_64__) || defined(__aarch64__) || defined(__POWERPC__))) \
144
+ || (defined(__BIONIC__) && (defined(__x86_64__) || defined(__i386__) || (defined(__arm__) && __ARM_ARCH >= 7) || defined(__aarch64__))) \
145
+ || (defined(__FreeBSD__) && (defined(__x86_64__) || defined(__i386__) || defined(__aarch64__))) \
146
+ || (defined(__OpenBSD__) && (defined(__x86_64__) || defined(__i386__) || defined(__aarch64__))) \
147
+ )
148
+
149
+ #define MI_HAS_TLS_SLOT 1
150
+
151
+ static inline void* mi_prim_tls_slot(size_t slot) mi_attr_noexcept {
152
+ void* res;
153
+ const size_t ofs = (slot*sizeof(void*));
154
+ #if defined(__i386__)
155
+ __asm__("movl %%gs:%1, %0" : "=r" (res) : "m" (*((void**)ofs)) : ); // x86 32-bit always uses GS
156
+ #elif defined(__APPLE__) && defined(__x86_64__)
157
+ __asm__("movq %%gs:%1, %0" : "=r" (res) : "m" (*((void**)ofs)) : ); // x86_64 macOSX uses GS
158
+ #elif defined(__x86_64__) && (MI_INTPTR_SIZE==4)
159
+ __asm__("movl %%fs:%1, %0" : "=r" (res) : "m" (*((void**)ofs)) : ); // x32 ABI
160
+ #elif defined(__x86_64__)
161
+ __asm__("movq %%fs:%1, %0" : "=r" (res) : "m" (*((void**)ofs)) : ); // x86_64 Linux, BSD uses FS
162
+ #elif defined(__arm__)
163
+ void** tcb; MI_UNUSED(ofs);
164
+ __asm__ volatile ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tcb));
165
+ res = tcb[slot];
166
+ #elif defined(__aarch64__)
167
+ void** tcb; MI_UNUSED(ofs);
168
+ #if defined(__APPLE__) // M1, issue #343
169
+ __asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tcb));
170
+ #else
171
+ __asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
172
+ #endif
173
+ res = tcb[slot];
174
+ #elif defined(__APPLE__) && defined(__POWERPC__) // ppc, issue #781
175
+ MI_UNUSED(ofs);
176
+ res = pthread_getspecific(slot);
177
+ #endif
178
+ return res;
179
+ }
180
+
181
+ // setting a tls slot is only used on macOS for now
182
+ static inline void mi_prim_tls_slot_set(size_t slot, void* value) mi_attr_noexcept {
183
+ const size_t ofs = (slot*sizeof(void*));
184
+ #if defined(__i386__)
185
+ __asm__("movl %1,%%gs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // 32-bit always uses GS
186
+ #elif defined(__APPLE__) && defined(__x86_64__)
187
+ __asm__("movq %1,%%gs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x86_64 macOS uses GS
188
+ #elif defined(__x86_64__) && (MI_INTPTR_SIZE==4)
189
+ __asm__("movl %1,%%fs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x32 ABI
190
+ #elif defined(__x86_64__)
191
+ __asm__("movq %1,%%fs:%0" : "=m" (*((void**)ofs)) : "rn" (value) : ); // x86_64 Linux, BSD uses FS
192
+ #elif defined(__arm__)
193
+ void** tcb; MI_UNUSED(ofs);
194
+ __asm__ volatile ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tcb));
195
+ tcb[slot] = value;
196
+ #elif defined(__aarch64__)
197
+ void** tcb; MI_UNUSED(ofs);
198
+ #if defined(__APPLE__) // M1, issue #343
199
+ __asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tcb));
200
+ #else
201
+ __asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
202
+ #endif
203
+ tcb[slot] = value;
204
+ #elif defined(__APPLE__) && defined(__POWERPC__) // ppc, issue #781
205
+ MI_UNUSED(ofs);
206
+ pthread_setspecific(slot, value);
207
+ #endif
208
+ }
209
+
210
+ #elif _WIN32 && MI_WIN_USE_FIXED_TLS && !defined(MI_WIN_USE_FLS)
211
+
212
+ // On windows we can store the thread-local heap at a fixed TLS slot to avoid
213
+ // thread-local initialization checks in the fast path.
214
+ // We allocate a user TLS slot at process initialization (see `windows/prim.c`)
215
+ // and store the offset `_mi_win_tls_offset`.
216
+ #define MI_HAS_TLS_SLOT 1 // 2 = we can reliably initialize the slot (saving a test on each malloc)
217
+
218
+ extern mi_decl_hidden size_t _mi_win_tls_offset;
219
+
220
+ #if MI_WIN_USE_FIXED_TLS > 1
221
+ #define MI_TLS_SLOT (MI_WIN_USE_FIXED_TLS)
222
+ #elif MI_SIZE_SIZE == 4
223
+ #define MI_TLS_SLOT (0x0E10 + _mi_win_tls_offset) // User TLS slots <https://en.wikipedia.org/wiki/Win32_Thread_Information_Block>
224
+ #else
225
+ #define MI_TLS_SLOT (0x1480 + _mi_win_tls_offset) // User TLS slots <https://en.wikipedia.org/wiki/Win32_Thread_Information_Block>
226
+ #endif
227
+
228
+ static inline void* mi_prim_tls_slot(size_t slot) mi_attr_noexcept {
229
+ #if (_M_X64 || _M_AMD64) && !defined(_M_ARM64EC)
230
+ return (void*)__readgsqword((unsigned long)slot); // direct load at offset from gs
231
+ #elif _M_IX86 && !defined(_M_ARM64EC)
232
+ return (void*)__readfsdword((unsigned long)slot); // direct load at offset from fs
233
+ #else
234
+ return ((void**)NtCurrentTeb())[slot / sizeof(void*)];
235
+ #endif
236
+ }
237
+ static inline void mi_prim_tls_slot_set(size_t slot, void* value) mi_attr_noexcept {
238
+ ((void**)NtCurrentTeb())[slot / sizeof(void*)] = value;
239
+ }
240
+
241
+ #endif
242
+
243
+
244
+
245
+ //-------------------------------------------------------------------
246
+ // Get a fast unique thread id.
247
+ //
248
+ // Getting the thread id should be performant as it is called in the
249
+ // fast path of `_mi_free` and we specialize for various platforms as
250
+ // inlined definitions. Regular code should call `init.c:_mi_thread_id()`.
251
+ // We only require _mi_prim_thread_id() to return a unique id
252
+ // for each thread (unequal to zero).
253
+ //-------------------------------------------------------------------
254
+
255
+
256
+ // Do we have __builtin_thread_pointer? This would be the preferred way to get a unique thread id
257
+ // but unfortunately, it seems we cannot test for this reliably at this time (see issue #883)
258
+ // Nevertheless, it seems needed on older graviton platforms (see issue #851).
259
+ // For now, we only enable this for specific platforms.
260
+ #if !defined(__APPLE__) /* on apple (M1) the wrong register is read (tpidr_el0 instead of tpidrro_el0) so fall back to TLS slot assembly (<https://github.com/microsoft/mimalloc/issues/343#issuecomment-763272369>)*/ \
261
+ && !defined(__CYGWIN__) \
262
+ && !defined(MI_LIBC_MUSL) \
263
+ && (!defined(__clang_major__) || __clang_major__ >= 14) /* older clang versions emit bad code; fall back to using the TLS slot (<https://lore.kernel.org/linux-arm-kernel/202110280952.352F66D8@keescook/T/>) */
264
+ #if (defined(__GNUC__) && (__GNUC__ >= 7) && defined(__aarch64__)) /* aarch64 for older gcc versions (issue #851) */ \
265
+ || (defined(__GNUC__) && (__GNUC__ >= 11) && defined(__x86_64__)) \
266
+ || (defined(__clang_major__) && (__clang_major__ >= 14) && (defined(__aarch64__) || defined(__x86_64__)))
267
+ #define MI_USE_BUILTIN_THREAD_POINTER 1
268
+ #endif
269
+ #endif
270
+
271
+
272
+
273
+ // defined in `init.c`; do not use these directly
274
+ extern mi_decl_hidden mi_decl_thread mi_heap_t* _mi_heap_default; // default heap to allocate from
275
+ extern mi_decl_hidden bool _mi_process_is_initialized; // has mi_process_init been called?
276
+
277
+ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept;
278
+
279
+ // Get a unique id for the current thread.
280
+ #if defined(MI_PRIM_THREAD_ID)
281
+
282
+ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
283
+ return MI_PRIM_THREAD_ID(); // used for example by CPython for a free threaded build (see python/cpython#115488)
284
+ }
285
+
286
+ #elif defined(_WIN32)
287
+
288
+ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
289
+ // Windows: works on Intel and ARM in both 32- and 64-bit
290
+ return (uintptr_t)NtCurrentTeb();
291
+ }
292
+
293
+ #elif MI_USE_BUILTIN_THREAD_POINTER
294
+
295
+ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
296
+ // Works on most Unix based platforms with recent compilers
297
+ return (uintptr_t)__builtin_thread_pointer();
298
+ }
299
+
300
+ #elif MI_HAS_TLS_SLOT
301
+
302
+ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
303
+ #if defined(__BIONIC__)
304
+ // issue #384, #495: on the Bionic libc (Android), slot 1 is the thread id
305
+ // see: https://github.com/aosp-mirror/platform_bionic/blob/c44b1d0676ded732df4b3b21c5f798eacae93228/libc/platform/bionic/tls_defines.h#L86
306
+ return (uintptr_t)mi_prim_tls_slot(1);
307
+ #else
308
+ // in all our other targets, slot 0 is the thread id
309
+ // glibc: https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=sysdeps/x86_64/nptl/tls.h
310
+ // apple: https://github.com/apple/darwin-xnu/blob/main/libsyscall/os/tsd.h#L36
311
+ return (uintptr_t)mi_prim_tls_slot(0);
312
+ #endif
313
+ }
314
+
315
+ #else
316
+
317
+ // otherwise use portable C, taking the address of a thread local variable (this is still very fast on most platforms).
318
+ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept {
319
+ return (uintptr_t)&_mi_heap_default;
320
+ }
321
+
322
+ #endif
323
+
324
+
325
+
326
+ /* ----------------------------------------------------------------------------------------
327
+ Get the thread local default heap: `_mi_prim_get_default_heap()`
328
+
329
+ This is inlined here as it is on the fast path for allocation functions.
330
+
331
+ On most platforms (Windows, Linux, FreeBSD, NetBSD, etc), this just returns a
332
+ __thread local variable (`_mi_heap_default`). With the initial-exec TLS model this ensures
333
+ that the storage will always be available (allocated on the thread stacks).
334
+
335
+ On some platforms though we cannot use that when overriding `malloc` since the underlying
336
+ TLS implementation (or the loader) will call itself `malloc` on a first access and recurse.
337
+ We try to circumvent this in an efficient way:
338
+ - macOSX : we use an unused TLS slot from the OS allocated slots (MI_TLS_SLOT). On OSX, the
339
+ loader itself calls `malloc` even before the modules are initialized.
340
+ - OpenBSD: we use an unused slot from the pthread block (MI_TLS_PTHREAD_SLOT_OFS).
341
+ - DragonFly: defaults are working but seem slow compared to freeBSD (see PR #323)
342
+ ------------------------------------------------------------------------------------------- */
343
+
344
+ static inline mi_heap_t* mi_prim_get_default_heap(void);
345
+
346
+ #if defined(MI_MALLOC_OVERRIDE)
347
+ #if defined(__APPLE__) // macOS
348
+ #define MI_TLS_SLOT 89 // seems unused?
349
+ // other possible unused ones are 9, 29, __PTK_FRAMEWORK_JAVASCRIPTCORE_KEY4 (94), __PTK_FRAMEWORK_GC_KEY9 (112) and __PTK_FRAMEWORK_OLDGC_KEY9 (89)
350
+ // see <https://github.com/rweichler/substrate/blob/master/include/pthread_machdep.h>
351
+ #elif defined(__OpenBSD__)
352
+ // use end bytes of a name; goes wrong if anyone uses names > 23 characters (ptrhread specifies 16)
353
+ // see <https://github.com/openbsd/src/blob/master/lib/libc/include/thread_private.h#L371>
354
+ #define MI_TLS_PTHREAD_SLOT_OFS (6*sizeof(int) + 4*sizeof(void*) + 24)
355
+ // #elif defined(__DragonFly__)
356
+ // #warning "mimalloc is not working correctly on DragonFly yet."
357
+ // #define MI_TLS_PTHREAD_SLOT_OFS (4 + 1*sizeof(void*)) // offset `uniqueid` (also used by gdb?) <https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/lib/libthread_xu/thread/thr_private.h#L458>
358
+ #elif defined(__ANDROID__)
359
+ // See issue #381
360
+ #define MI_TLS_PTHREAD
361
+ #endif
362
+ #endif
363
+
364
+
365
+ #if MI_TLS_SLOT
366
+ # if !defined(MI_HAS_TLS_SLOT)
367
+ # error "trying to use a TLS slot for the default heap, but the mi_prim_tls_slot primitives are not defined"
368
+ # endif
369
+
370
+ static inline mi_heap_t* mi_prim_get_default_heap(void) {
371
+ mi_heap_t* heap = (mi_heap_t*)mi_prim_tls_slot(MI_TLS_SLOT);
372
+ #if MI_HAS_TLS_SLOT == 1 // check if the TLS slot is initialized
373
+ if mi_unlikely(heap == NULL) {
374
+ #ifdef __GNUC__
375
+ __asm(""); // prevent conditional load of the address of _mi_heap_empty
376
+ #endif
377
+ heap = (mi_heap_t*)&_mi_heap_empty;
378
+ }
379
+ #endif
380
+ return heap;
381
+ }
382
+
383
+ #elif defined(MI_TLS_PTHREAD_SLOT_OFS)
384
+
385
+ static inline mi_heap_t** mi_prim_tls_pthread_heap_slot(void) {
386
+ pthread_t self = pthread_self();
387
+ #if defined(__DragonFly__)
388
+ if (self==NULL) return NULL;
389
+ #endif
390
+ return (mi_heap_t**)((uint8_t*)self + MI_TLS_PTHREAD_SLOT_OFS);
391
+ }
392
+
393
+ static inline mi_heap_t* mi_prim_get_default_heap(void) {
394
+ mi_heap_t** pheap = mi_prim_tls_pthread_heap_slot();
395
+ if mi_unlikely(pheap == NULL) return _mi_heap_main_get();
396
+ mi_heap_t* heap = *pheap;
397
+ if mi_unlikely(heap == NULL) return (mi_heap_t*)&_mi_heap_empty;
398
+ return heap;
399
+ }
400
+
401
+ #elif defined(MI_TLS_PTHREAD)
402
+
403
+ extern mi_decl_hidden pthread_key_t _mi_heap_default_key;
404
+ static inline mi_heap_t* mi_prim_get_default_heap(void) {
405
+ mi_heap_t* heap = (mi_unlikely(_mi_heap_default_key == (pthread_key_t)(-1)) ? _mi_heap_main_get() : (mi_heap_t*)pthread_getspecific(_mi_heap_default_key));
406
+ return (mi_unlikely(heap == NULL) ? (mi_heap_t*)&_mi_heap_empty : heap);
407
+ }
408
+
409
+ #else // default using a thread local variable; used on most platforms.
410
+
411
+ static inline mi_heap_t* mi_prim_get_default_heap(void) {
412
+ #if defined(MI_TLS_RECURSE_GUARD)
413
+ if (mi_unlikely(!_mi_process_is_initialized)) return _mi_heap_main_get();
414
+ #endif
415
+ return _mi_heap_default;
416
+ }
417
+
418
+ #endif // mi_prim_get_default_heap()
419
+
420
+
421
+ #endif // MIMALLOC_PRIM_H
@@ -0,0 +1,145 @@
1
+ /* ----------------------------------------------------------------------------
2
+ Copyright (c) 2018-2023, Microsoft Research, Daan Leijen
3
+ This is free software; you can redistribute it and/or modify it under the
4
+ terms of the MIT license. A copy of the license can be found in the file
5
+ "LICENSE" at the root of this distribution.
6
+ -----------------------------------------------------------------------------*/
7
+ #pragma once
8
+ #ifndef MIMALLOC_TRACK_H
9
+ #define MIMALLOC_TRACK_H
10
+
11
+ /* ------------------------------------------------------------------------------------------------------
12
+ Track memory ranges with macros for tools like Valgrind address sanitizer, or other memory checkers.
13
+ These can be defined for tracking allocation:
14
+
15
+ #define mi_track_malloc_size(p,reqsize,size,zero)
16
+ #define mi_track_free_size(p,_size)
17
+
18
+ The macros are set up such that the size passed to `mi_track_free_size`
19
+ always matches the size of `mi_track_malloc_size`. (currently, `size == mi_usable_size(p)`).
20
+ The `reqsize` is what the user requested, and `size >= reqsize`.
21
+ The `size` is either byte precise (and `size==reqsize`) if `MI_PADDING` is enabled,
22
+ or otherwise it is the usable block size which may be larger than the original request.
23
+ Use `_mi_block_size_of(void* p)` to get the full block size that was allocated (including padding etc).
24
+ The `zero` parameter is `true` if the allocated block is zero initialized.
25
+
26
+ Optional:
27
+
28
+ #define mi_track_align(p,alignedp,offset,size)
29
+ #define mi_track_resize(p,oldsize,newsize)
30
+ #define mi_track_init()
31
+
32
+ The `mi_track_align` is called right after a `mi_track_malloc` for aligned pointers in a block.
33
+ The corresponding `mi_track_free` still uses the block start pointer and original size (corresponding to the `mi_track_malloc`).
34
+ The `mi_track_resize` is currently unused but could be called on reallocations within a block.
35
+ `mi_track_init` is called at program start.
36
+
37
+ The following macros are for tools like asan and valgrind to track whether memory is
38
+ defined, undefined, or not accessible at all:
39
+
40
+ #define mi_track_mem_defined(p,size)
41
+ #define mi_track_mem_undefined(p,size)
42
+ #define mi_track_mem_noaccess(p,size)
43
+
44
+ -------------------------------------------------------------------------------------------------------*/
45
+
46
+ #if MI_TRACK_VALGRIND
47
+ // valgrind tool
48
+
49
+ #define MI_TRACK_ENABLED 1
50
+ #define MI_TRACK_HEAP_DESTROY 1 // track free of individual blocks on heap_destroy
51
+ #define MI_TRACK_TOOL "valgrind"
52
+
53
+ #include <valgrind/valgrind.h>
54
+ #include <valgrind/memcheck.h>
55
+
56
+ #define mi_track_malloc_size(p,reqsize,size,zero) VALGRIND_MALLOCLIKE_BLOCK(p,size,MI_PADDING_SIZE /*red zone*/,zero)
57
+ #define mi_track_free_size(p,_size) VALGRIND_FREELIKE_BLOCK(p,MI_PADDING_SIZE /*red zone*/)
58
+ #define mi_track_resize(p,oldsize,newsize) VALGRIND_RESIZEINPLACE_BLOCK(p,oldsize,newsize,MI_PADDING_SIZE /*red zone*/)
59
+ #define mi_track_mem_defined(p,size) VALGRIND_MAKE_MEM_DEFINED(p,size)
60
+ #define mi_track_mem_undefined(p,size) VALGRIND_MAKE_MEM_UNDEFINED(p,size)
61
+ #define mi_track_mem_noaccess(p,size) VALGRIND_MAKE_MEM_NOACCESS(p,size)
62
+
63
+ #elif MI_TRACK_ASAN
64
+ // address sanitizer
65
+
66
+ #define MI_TRACK_ENABLED 1
67
+ #define MI_TRACK_HEAP_DESTROY 0
68
+ #define MI_TRACK_TOOL "asan"
69
+
70
+ #include <sanitizer/asan_interface.h>
71
+
72
+ #define mi_track_malloc_size(p,reqsize,size,zero) ASAN_UNPOISON_MEMORY_REGION(p,size)
73
+ #define mi_track_free_size(p,size) ASAN_POISON_MEMORY_REGION(p,size)
74
+ #define mi_track_mem_defined(p,size) ASAN_UNPOISON_MEMORY_REGION(p,size)
75
+ #define mi_track_mem_undefined(p,size) ASAN_UNPOISON_MEMORY_REGION(p,size)
76
+ #define mi_track_mem_noaccess(p,size) ASAN_POISON_MEMORY_REGION(p,size)
77
+
78
+ #elif MI_TRACK_ETW
79
+ // windows event tracing
80
+
81
+ #define MI_TRACK_ENABLED 1
82
+ #define MI_TRACK_HEAP_DESTROY 1
83
+ #define MI_TRACK_TOOL "ETW"
84
+
85
+ #include "../src/prim/windows/etw.h"
86
+
87
+ #define mi_track_init() EventRegistermicrosoft_windows_mimalloc();
88
+ #define mi_track_malloc_size(p,reqsize,size,zero) EventWriteETW_MI_ALLOC((UINT64)(p), size)
89
+ #define mi_track_free_size(p,size) EventWriteETW_MI_FREE((UINT64)(p), size)
90
+
91
+ #else
92
+ // no tracking
93
+
94
+ #define MI_TRACK_ENABLED 0
95
+ #define MI_TRACK_HEAP_DESTROY 0
96
+ #define MI_TRACK_TOOL "none"
97
+
98
+ #define mi_track_malloc_size(p,reqsize,size,zero)
99
+ #define mi_track_free_size(p,_size)
100
+
101
+ #endif
102
+
103
+ // -------------------
104
+ // Utility definitions
105
+
106
+ #ifndef mi_track_resize
107
+ #define mi_track_resize(p,oldsize,newsize) mi_track_free_size(p,oldsize); mi_track_malloc(p,newsize,false)
108
+ #endif
109
+
110
+ #ifndef mi_track_align
111
+ #define mi_track_align(p,alignedp,offset,size) mi_track_mem_noaccess(p,offset)
112
+ #endif
113
+
114
+ #ifndef mi_track_init
115
+ #define mi_track_init()
116
+ #endif
117
+
118
+ #ifndef mi_track_mem_defined
119
+ #define mi_track_mem_defined(p,size)
120
+ #endif
121
+
122
+ #ifndef mi_track_mem_undefined
123
+ #define mi_track_mem_undefined(p,size)
124
+ #endif
125
+
126
+ #ifndef mi_track_mem_noaccess
127
+ #define mi_track_mem_noaccess(p,size)
128
+ #endif
129
+
130
+
131
+ #if MI_PADDING
132
+ #define mi_track_malloc(p,reqsize,zero) \
133
+ if ((p)!=NULL) { \
134
+ mi_assert_internal(mi_usable_size(p)==(reqsize)); \
135
+ mi_track_malloc_size(p,reqsize,reqsize,zero); \
136
+ }
137
+ #else
138
+ #define mi_track_malloc(p,reqsize,zero) \
139
+ if ((p)!=NULL) { \
140
+ mi_assert_internal(mi_usable_size(p)>=(reqsize)); \
141
+ mi_track_malloc_size(p,reqsize,mi_usable_size(p),zero); \
142
+ }
143
+ #endif
144
+
145
+ #endif