@zigc/lib 0.16.0-test.1 → 0.17.0-dev.131

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 (352) hide show
  1. package/LICENSE +19 -0
  2. package/c/fcntl.zig +6 -1
  3. package/c/inttypes.zig +0 -10
  4. package/c/math.zig +138 -114
  5. package/c/pthread.zig +57 -0
  6. package/c/search.zig +1 -27
  7. package/c/stdlib/drand48.zig +0 -57
  8. package/c/stdlib.zig +0 -100
  9. package/c/string.zig +20 -7
  10. package/c/strings.zig +0 -38
  11. package/c/stropts.zig +17 -0
  12. package/c/unistd.zig +27 -26
  13. package/c/wchar.zig +10 -0
  14. package/c.zig +3 -2
  15. package/compiler/aro/aro/Attribute/names.zig +604 -589
  16. package/compiler/aro/aro/Attribute.zig +202 -116
  17. package/compiler/aro/aro/Builtins/common.zig +874 -863
  18. package/compiler/aro/aro/Builtins/eval.zig +15 -7
  19. package/compiler/aro/aro/Builtins.zig +0 -1
  20. package/compiler/aro/aro/CodeGen.zig +8 -7
  21. package/compiler/aro/aro/Compilation.zig +137 -111
  22. package/compiler/aro/aro/Diagnostics.zig +21 -17
  23. package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
  24. package/compiler/aro/aro/Driver.zig +138 -63
  25. package/compiler/aro/aro/LangOpts.zig +12 -2
  26. package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
  27. package/compiler/aro/aro/Parser.zig +352 -153
  28. package/compiler/aro/aro/Pragma.zig +3 -2
  29. package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
  30. package/compiler/aro/aro/Preprocessor.zig +136 -62
  31. package/compiler/aro/aro/Target.zig +17 -12
  32. package/compiler/aro/aro/Tokenizer.zig +31 -14
  33. package/compiler/aro/aro/Toolchain.zig +4 -7
  34. package/compiler/aro/aro/Tree.zig +178 -148
  35. package/compiler/aro/aro/TypeStore.zig +82 -24
  36. package/compiler/aro/aro/Value.zig +13 -17
  37. package/compiler/aro/aro/features.zig +1 -0
  38. package/compiler/aro/aro/pragmas/message.zig +3 -2
  39. package/compiler/aro/aro/pragmas/once.zig +0 -1
  40. package/compiler/aro/aro/record_layout.zig +3 -3
  41. package/compiler/aro/aro/text_literal.zig +3 -2
  42. package/compiler/aro/assembly_backend/x86_64.zig +7 -8
  43. package/compiler/aro/backend/Assembly.zig +1 -2
  44. package/compiler/aro/backend/Interner.zig +2 -2
  45. package/compiler/aro/backend/Ir.zig +100 -92
  46. package/compiler/aro/include/ptrcheck.h +49 -0
  47. package/compiler/aro/main.zig +26 -10
  48. package/compiler/build_runner.zig +1 -2
  49. package/compiler/objdump.zig +93 -0
  50. package/compiler/reduce/Walk.zig +7 -7
  51. package/compiler/reduce.zig +5 -1
  52. package/compiler/resinator/compile.zig +2 -2
  53. package/compiler/resinator/main.zig +7 -1
  54. package/compiler/resinator/preprocess.zig +1 -3
  55. package/compiler/std-docs.zig +8 -1
  56. package/compiler/test_runner.zig +194 -62
  57. package/compiler/translate-c/MacroTranslator.zig +80 -11
  58. package/compiler/translate-c/PatternList.zig +1 -9
  59. package/compiler/translate-c/Scope.zig +43 -6
  60. package/compiler/translate-c/Translator.zig +369 -127
  61. package/compiler/translate-c/ast.zig +19 -11
  62. package/compiler/translate-c/main.zig +76 -17
  63. package/compiler_rt/cos.zig +140 -53
  64. package/compiler_rt/divmodei4.zig +40 -17
  65. package/compiler_rt/exp.zig +1 -6
  66. package/compiler_rt/exp2.zig +1 -6
  67. package/compiler_rt/exp_f128.zig +377 -0
  68. package/compiler_rt/fabs.zig +0 -2
  69. package/compiler_rt/fma.zig +0 -2
  70. package/compiler_rt/fmax.zig +0 -2
  71. package/compiler_rt/fmin.zig +0 -2
  72. package/compiler_rt/fmod.zig +0 -2
  73. package/compiler_rt/limb64.zig +1127 -0
  74. package/compiler_rt/log.zig +0 -2
  75. package/compiler_rt/log10.zig +0 -2
  76. package/compiler_rt/log2.zig +0 -2
  77. package/compiler_rt/long_double.zig +37 -0
  78. package/compiler_rt/mulXi3.zig +1 -1
  79. package/compiler_rt/mulo.zig +6 -1
  80. package/compiler_rt/rem_pio2l.zig +173 -0
  81. package/compiler_rt/round.zig +0 -2
  82. package/compiler_rt/sin.zig +139 -56
  83. package/compiler_rt/sincos.zig +277 -72
  84. package/compiler_rt/sqrt.zig +0 -2
  85. package/compiler_rt/ssp.zig +1 -1
  86. package/compiler_rt/tan.zig +117 -48
  87. package/compiler_rt/trig.zig +256 -6
  88. package/compiler_rt/trunc.zig +0 -2
  89. package/compiler_rt/udivmodei4.zig +28 -0
  90. package/compiler_rt.zig +2 -0
  91. package/fuzzer.zig +857 -307
  92. package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
  93. package/libc/musl/src/math/pow.c +343 -0
  94. package/package.json +1 -1
  95. package/std/Build/Cache.zig +6 -6
  96. package/std/Build/Fuzz.zig +6 -19
  97. package/std/Build/Module.zig +1 -1
  98. package/std/Build/Step/CheckObject.zig +3 -3
  99. package/std/Build/Step/Compile.zig +18 -1
  100. package/std/Build/Step/ConfigHeader.zig +49 -33
  101. package/std/Build/Step/InstallArtifact.zig +18 -0
  102. package/std/Build/Step/Run.zig +538 -89
  103. package/std/Build/Step/TranslateC.zig +0 -6
  104. package/std/Build/Step.zig +10 -19
  105. package/std/Build/WebServer.zig +31 -19
  106. package/std/Build/abi.zig +47 -11
  107. package/std/Build.zig +17 -17
  108. package/std/Io/Dir.zig +7 -2
  109. package/std/Io/Dispatch.zig +5 -13
  110. package/std/Io/File/Reader.zig +3 -1
  111. package/std/Io/File/Writer.zig +8 -6
  112. package/std/Io/File.zig +1 -0
  113. package/std/Io/Kqueue.zig +2 -2
  114. package/std/Io/Reader.zig +8 -9
  115. package/std/Io/Semaphore.zig +112 -17
  116. package/std/Io/Terminal.zig +1 -1
  117. package/std/Io/Threaded.zig +352 -180
  118. package/std/Io/Uring.zig +15 -16
  119. package/std/Io/Writer.zig +46 -42
  120. package/std/Io/net.zig +11 -11
  121. package/std/Io.zig +1052 -20
  122. package/std/SemanticVersion.zig +1 -1
  123. package/std/Target/Query.zig +2 -2
  124. package/std/Target.zig +53 -7
  125. package/std/Thread.zig +8 -3
  126. package/std/array_hash_map.zig +105 -573
  127. package/std/array_list.zig +22 -31
  128. package/std/bit_set.zig +22 -6
  129. package/std/builtin/assembly.zig +68 -0
  130. package/std/builtin.zig +4 -0
  131. package/std/c/haiku.zig +3 -0
  132. package/std/c/serenity.zig +1 -6
  133. package/std/c.zig +106 -24
  134. package/std/compress/flate/Compress.zig +3 -3
  135. package/std/compress/flate/Decompress.zig +2 -3
  136. package/std/compress/zstd/Decompress.zig +2 -4
  137. package/std/crypto/Certificate/Bundle.zig +15 -1
  138. package/std/crypto/Certificate.zig +13 -1
  139. package/std/crypto/ascon.zig +75 -33
  140. package/std/crypto/codecs/asn1/Oid.zig +12 -1
  141. package/std/crypto/codecs/asn1.zig +33 -18
  142. package/std/crypto/codecs/base64_hex_ct.zig +16 -8
  143. package/std/crypto/ml_kem.zig +2 -9
  144. package/std/crypto/tls/Client.zig +79 -4
  145. package/std/crypto/tls.zig +1 -1
  146. package/std/crypto.zig +1 -0
  147. package/std/debug/Dwarf.zig +29 -9
  148. package/std/debug/Info.zig +4 -0
  149. package/std/debug/MachOFile.zig +46 -8
  150. package/std/debug/Pdb.zig +540 -37
  151. package/std/debug/SelfInfo/Elf.zig +19 -18
  152. package/std/debug/SelfInfo/MachO.zig +18 -7
  153. package/std/debug/SelfInfo/Windows.zig +138 -36
  154. package/std/debug.zig +181 -66
  155. package/std/enums.zig +25 -19
  156. package/std/fmt.zig +8 -3
  157. package/std/fs/path.zig +6 -4
  158. package/std/heap/ArenaAllocator.zig +145 -154
  159. package/std/heap/BufferFirstAllocator.zig +165 -0
  160. package/std/heap/debug_allocator.zig +7 -7
  161. package/std/heap.zig +2 -126
  162. package/std/http/Client.zig +31 -30
  163. package/std/http.zig +14 -13
  164. package/std/json/Scanner.zig +2 -2
  165. package/std/json/Stringify.zig +3 -3
  166. package/std/json/dynamic.zig +4 -4
  167. package/std/math/big/int.zig +16 -17
  168. package/std/mem/Allocator.zig +4 -5
  169. package/std/mem.zig +48 -0
  170. package/std/os/emscripten.zig +2 -18
  171. package/std/os/linux/IoUring.zig +2 -0
  172. package/std/os/linux/aarch64.zig +41 -12
  173. package/std/os/linux/arc.zig +173 -0
  174. package/std/os/linux/arm.zig +41 -12
  175. package/std/os/linux/hexagon.zig +33 -11
  176. package/std/os/linux/loongarch32.zig +41 -13
  177. package/std/os/linux/loongarch64.zig +41 -12
  178. package/std/os/linux/m68k.zig +41 -13
  179. package/std/os/linux/mips.zig +67 -36
  180. package/std/os/linux/mips64.zig +60 -29
  181. package/std/os/linux/mipsn32.zig +60 -29
  182. package/std/os/linux/or1k.zig +41 -12
  183. package/std/os/linux/powerpc.zig +41 -12
  184. package/std/os/linux/powerpc64.zig +41 -12
  185. package/std/os/linux/riscv32.zig +41 -12
  186. package/std/os/linux/riscv64.zig +41 -12
  187. package/std/os/linux/s390x.zig +44 -7
  188. package/std/os/linux/sparc64.zig +83 -52
  189. package/std/os/linux/thumb.zig +52 -36
  190. package/std/os/linux/x32.zig +41 -12
  191. package/std/os/linux/x86.zig +42 -13
  192. package/std/os/linux/x86_64.zig +41 -12
  193. package/std/os/linux.zig +419 -438
  194. package/std/os/uefi/tables/boot_services.zig +9 -8
  195. package/std/os/windows.zig +2 -2
  196. package/std/os.zig +41 -0
  197. package/std/pdb.zig +143 -4
  198. package/std/posix.zig +6 -12
  199. package/std/priority_dequeue.zig +13 -12
  200. package/std/priority_queue.zig +5 -4
  201. package/std/process/Child.zig +1 -1
  202. package/std/process/Environ.zig +1 -1
  203. package/std/process.zig +1 -1
  204. package/std/sort.zig +3 -3
  205. package/std/start.zig +17 -4
  206. package/std/std.zig +19 -6
  207. package/std/testing/FailingAllocator.zig +4 -4
  208. package/std/testing/Smith.zig +37 -2
  209. package/std/zig/Ast/Render.zig +187 -459
  210. package/std/zig/Ast.zig +0 -4
  211. package/std/zig/AstGen.zig +86 -103
  212. package/std/zig/AstRlAnnotate.zig +0 -11
  213. package/std/zig/AstSmith.zig +2602 -0
  214. package/std/zig/BuiltinFn.zig +0 -32
  215. package/std/zig/Client.zig +8 -3
  216. package/std/zig/LibCInstallation.zig +4 -3
  217. package/std/zig/Parse.zig +90 -81
  218. package/std/zig/Server.zig +26 -0
  219. package/std/zig/WindowsSdk.zig +13 -13
  220. package/std/zig/Zir.zig +66 -62
  221. package/std/zig/ZonGen.zig +6 -5
  222. package/std/zig/c_translation/helpers.zig +14 -9
  223. package/std/zig/llvm/Builder.zig +119 -60
  224. package/std/zig/system.zig +20 -4
  225. package/std/zig/tokenizer.zig +2 -1
  226. package/std/zig.zig +7 -10
  227. package/std/zip.zig +5 -5
  228. package/zig.h +340 -1
  229. package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
  230. package/libc/mingw/complex/cabs.c +0 -48
  231. package/libc/mingw/complex/cabsf.c +0 -48
  232. package/libc/mingw/complex/cacos.c +0 -50
  233. package/libc/mingw/complex/cacosf.c +0 -50
  234. package/libc/mingw/complex/carg.c +0 -48
  235. package/libc/mingw/complex/cargf.c +0 -48
  236. package/libc/mingw/complex/casin.c +0 -50
  237. package/libc/mingw/complex/casinf.c +0 -50
  238. package/libc/mingw/complex/catan.c +0 -50
  239. package/libc/mingw/complex/catanf.c +0 -50
  240. package/libc/mingw/complex/ccos.c +0 -50
  241. package/libc/mingw/complex/ccosf.c +0 -50
  242. package/libc/mingw/complex/cexp.c +0 -48
  243. package/libc/mingw/complex/cexpf.c +0 -48
  244. package/libc/mingw/complex/cimag.c +0 -48
  245. package/libc/mingw/complex/cimagf.c +0 -48
  246. package/libc/mingw/complex/clog.c +0 -48
  247. package/libc/mingw/complex/clog10.c +0 -49
  248. package/libc/mingw/complex/clog10f.c +0 -49
  249. package/libc/mingw/complex/clogf.c +0 -48
  250. package/libc/mingw/complex/conj.c +0 -48
  251. package/libc/mingw/complex/conjf.c +0 -48
  252. package/libc/mingw/complex/cpow.c +0 -48
  253. package/libc/mingw/complex/cpowf.c +0 -48
  254. package/libc/mingw/complex/cproj.c +0 -48
  255. package/libc/mingw/complex/cprojf.c +0 -48
  256. package/libc/mingw/complex/creal.c +0 -48
  257. package/libc/mingw/complex/crealf.c +0 -48
  258. package/libc/mingw/complex/csin.c +0 -50
  259. package/libc/mingw/complex/csinf.c +0 -50
  260. package/libc/mingw/complex/csqrt.c +0 -48
  261. package/libc/mingw/complex/csqrtf.c +0 -48
  262. package/libc/mingw/complex/ctan.c +0 -50
  263. package/libc/mingw/complex/ctanf.c +0 -50
  264. package/libc/mingw/math/arm/s_rint.c +0 -86
  265. package/libc/mingw/math/arm/s_rintf.c +0 -51
  266. package/libc/mingw/math/arm/sincos.S +0 -30
  267. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  268. package/libc/mingw/math/arm64/rint.c +0 -12
  269. package/libc/mingw/math/arm64/rintf.c +0 -12
  270. package/libc/mingw/math/arm64/sincos.S +0 -32
  271. package/libc/mingw/math/bsd_private_base.h +0 -148
  272. package/libc/mingw/math/fdiml.c +0 -24
  273. package/libc/mingw/math/frexpf.c +0 -13
  274. package/libc/mingw/math/frexpl.c +0 -71
  275. package/libc/mingw/math/x86/acosf.c +0 -29
  276. package/libc/mingw/math/x86/atanf.c +0 -23
  277. package/libc/mingw/math/x86/atanl.c +0 -18
  278. package/libc/mingw/math/x86/cos.def.h +0 -65
  279. package/libc/mingw/math/x86/cosl.c +0 -46
  280. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  281. package/libc/mingw/math/x86/ldexp.c +0 -23
  282. package/libc/mingw/math/x86/scalbn.S +0 -41
  283. package/libc/mingw/math/x86/scalbnf.S +0 -40
  284. package/libc/mingw/math/x86/sin.def.h +0 -65
  285. package/libc/mingw/math/x86/sinl.c +0 -46
  286. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  287. package/libc/mingw/math/x86/tanl.S +0 -62
  288. package/libc/mingw/misc/btowc.c +0 -28
  289. package/libc/mingw/misc/wcstof.c +0 -66
  290. package/libc/mingw/misc/wcstoimax.c +0 -132
  291. package/libc/mingw/misc/wcstoumax.c +0 -126
  292. package/libc/mingw/misc/wctob.c +0 -29
  293. package/libc/mingw/misc/winbs_uint64.c +0 -6
  294. package/libc/mingw/misc/winbs_ulong.c +0 -6
  295. package/libc/mingw/misc/winbs_ushort.c +0 -6
  296. package/libc/mingw/stdio/_Exit.c +0 -10
  297. package/libc/mingw/stdio/_findfirst64i32.c +0 -21
  298. package/libc/mingw/stdio/_findnext64i32.c +0 -21
  299. package/libc/mingw/stdio/_fstat64i32.c +0 -37
  300. package/libc/mingw/stdio/_stat64i32.c +0 -37
  301. package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
  302. package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
  303. package/libc/mingw/stdio/_wstat64i32.c +0 -37
  304. package/libc/mingw/winpthreads/spinlock.c +0 -82
  305. package/libc/musl/src/legacy/isastream.c +0 -7
  306. package/libc/musl/src/legacy/valloc.c +0 -8
  307. package/libc/musl/src/linux/tee.c +0 -8
  308. package/libc/musl/src/math/__cosl.c +0 -96
  309. package/libc/musl/src/math/__sinl.c +0 -78
  310. package/libc/musl/src/math/__tanl.c +0 -143
  311. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  312. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  313. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  314. package/libc/musl/src/math/cosl.c +0 -39
  315. package/libc/musl/src/math/fdim.c +0 -10
  316. package/libc/musl/src/math/fdimf.c +0 -10
  317. package/libc/musl/src/math/fdiml.c +0 -18
  318. package/libc/musl/src/math/finite.c +0 -7
  319. package/libc/musl/src/math/finitef.c +0 -7
  320. package/libc/musl/src/math/frexp.c +0 -23
  321. package/libc/musl/src/math/frexpf.c +0 -23
  322. package/libc/musl/src/math/frexpl.c +0 -29
  323. package/libc/musl/src/math/i386/lrint.c +0 -8
  324. package/libc/musl/src/math/i386/lrintf.c +0 -8
  325. package/libc/musl/src/math/i386/rintf.c +0 -7
  326. package/libc/musl/src/math/lrint.c +0 -72
  327. package/libc/musl/src/math/lrintf.c +0 -8
  328. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  329. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  330. package/libc/musl/src/math/rintf.c +0 -30
  331. package/libc/musl/src/math/s390x/rintf.c +0 -15
  332. package/libc/musl/src/math/sincosl.c +0 -60
  333. package/libc/musl/src/math/sinl.c +0 -41
  334. package/libc/musl/src/math/tanl.c +0 -29
  335. package/libc/musl/src/math/x32/lrint.s +0 -5
  336. package/libc/musl/src/math/x32/lrintf.s +0 -5
  337. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  338. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
  339. package/libc/musl/src/string/strdup.c +0 -10
  340. package/libc/musl/src/string/strndup.c +0 -12
  341. package/libc/musl/src/string/wcsdup.c +0 -10
  342. package/libc/musl/src/thread/pthread_spin_destroy.c +0 -6
  343. package/libc/musl/src/thread/pthread_spin_init.c +0 -6
  344. package/libc/musl/src/thread/pthread_spin_lock.c +0 -8
  345. package/libc/musl/src/thread/pthread_spin_trylock.c +0 -7
  346. package/libc/musl/src/thread/pthread_spin_unlock.c +0 -7
  347. package/libc/musl/src/unistd/dup2.c +0 -20
  348. package/libc/musl/src/unistd/dup3.c +0 -26
  349. package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
  350. package/libc/wasi/thread-stub/pthread_spin_lock.c +0 -8
  351. package/libc/wasi/thread-stub/pthread_spin_trylock.c +0 -8
  352. package/libc/wasi/thread-stub/pthread_spin_unlock.c +0 -7
@@ -681,6 +681,8 @@ pub const AsconXof128 = struct {
681
681
 
682
682
  st: AsconState,
683
683
  squeezed: bool,
684
+ buf: [block_length]u8,
685
+ buf_len: usize,
684
686
 
685
687
  pub const Options = struct {};
686
688
 
@@ -698,7 +700,7 @@ pub const AsconXof128 = struct {
698
700
  const words: [5]u64 = .{ iv, 0, 0, 0, 0 };
699
701
  var st = AsconState.initFromWords(words);
700
702
  st.permuteR(12);
701
- return AsconXof128{ .st = st, .squeezed = false };
703
+ return AsconXof128{ .st = st, .squeezed = false, .buf = @splat(0), .buf_len = 0 };
702
704
  }
703
705
 
704
706
  /// Hash a slice of bytes with variable-length output.
@@ -726,24 +728,26 @@ pub const AsconXof128 = struct {
726
728
 
727
729
  var i: usize = 0;
728
730
 
729
- // Process full 64-bit blocks
730
- while (i + 8 <= b.len) : (i += 8) {
731
- self.st.addBytes(b[i..][0..8]);
731
+ if (self.buf_len > 0) {
732
+ const to_fill = @min(block_length - self.buf_len, b.len);
733
+ @memcpy(self.buf[self.buf_len..][0..to_fill], b[0..to_fill]);
734
+ self.buf_len += to_fill;
735
+ i += to_fill;
736
+ if (self.buf_len == block_length) {
737
+ self.st.addBytes(&self.buf);
738
+ self.st.permuteR(12);
739
+ self.buf_len = 0;
740
+ }
741
+ }
742
+
743
+ while (i + block_length <= b.len) : (i += block_length) {
744
+ self.st.addBytes(b[i..][0..block_length]);
732
745
  self.st.permuteR(12);
733
746
  }
734
747
 
735
- // Store partial block for finalization
736
748
  if (i < b.len) {
737
- var padded: [8]u8 = @splat(0);
738
- const remaining = b.len - i;
739
- @memcpy(padded[0..remaining], b[i..]);
740
- padded[remaining] = 0x01;
741
- self.st.addBytes(&padded);
742
- } else {
743
- // Add padding block
744
- var padded: [8]u8 = @splat(0);
745
- padded[0] = 0x01;
746
- self.st.addBytes(&padded);
749
+ self.buf_len = b.len - i;
750
+ @memcpy(self.buf[0..self.buf_len], b[i..]);
747
751
  }
748
752
  }
749
753
 
@@ -756,7 +760,10 @@ pub const AsconXof128 = struct {
756
760
  /// After first call, no more data can be absorbed with update().
757
761
  pub fn squeeze(self: *AsconXof128, out: []u8) void {
758
762
  if (!self.squeezed) {
759
- // First squeeze - apply final permutation
763
+ var padded: [block_length]u8 = @splat(0);
764
+ @memcpy(padded[0..self.buf_len], self.buf[0..self.buf_len]);
765
+ padded[self.buf_len] = 0x01;
766
+ self.st.addBytes(&padded);
760
767
  self.st.permuteR(12);
761
768
  self.squeezed = true;
762
769
  }
@@ -783,6 +790,8 @@ pub const AsconCxof128 = struct {
783
790
 
784
791
  st: AsconState,
785
792
  squeezed: bool,
793
+ buf: [block_length]u8,
794
+ buf_len: usize,
786
795
 
787
796
  pub const Options = struct { custom: []const u8 = "" };
788
797
 
@@ -804,7 +813,7 @@ pub const AsconCxof128 = struct {
804
813
  var st = AsconState.initFromWords(words);
805
814
  st.permuteR(12);
806
815
 
807
- var self = AsconCxof128{ .st = st, .squeezed = false };
816
+ var self = AsconCxof128{ .st = st, .squeezed = false, .buf = @splat(0), .buf_len = 0 };
808
817
 
809
818
  // Process customization string - always process length and padding
810
819
  // First block: length of customization string
@@ -867,28 +876,30 @@ pub const AsconCxof128 = struct {
867
876
  ///
868
877
  /// Note: Cannot be called after squeeze() has been called
869
878
  pub fn update(self: *AsconCxof128, b: []const u8) void {
870
- debug.assert(!self.squeezed);
879
+ debug.assert(!self.squeezed); // Cannot update after squeezing
871
880
 
872
881
  var i: usize = 0;
873
882
 
874
- // Process full 64-bit blocks
875
- while (i + 8 <= b.len) : (i += 8) {
876
- self.st.addBytes(b[i..][0..8]);
883
+ if (self.buf_len > 0) {
884
+ const to_fill = @min(block_length - self.buf_len, b.len);
885
+ @memcpy(self.buf[self.buf_len..][0..to_fill], b[0..to_fill]);
886
+ self.buf_len += to_fill;
887
+ i += to_fill;
888
+ if (self.buf_len == block_length) {
889
+ self.st.addBytes(&self.buf);
890
+ self.st.permuteR(12);
891
+ self.buf_len = 0;
892
+ }
893
+ }
894
+
895
+ while (i + block_length <= b.len) : (i += block_length) {
896
+ self.st.addBytes(b[i..][0..block_length]);
877
897
  self.st.permuteR(12);
878
898
  }
879
899
 
880
- // Store partial block for finalization
881
900
  if (i < b.len) {
882
- var padded: [8]u8 = @splat(0);
883
- const remaining = b.len - i;
884
- @memcpy(padded[0..remaining], b[i..]);
885
- padded[remaining] = 0x01;
886
- self.st.addBytes(&padded);
887
- } else {
888
- // Add padding block
889
- var padded: [8]u8 = @splat(0);
890
- padded[0] = 0x01;
891
- self.st.addBytes(&padded);
901
+ self.buf_len = b.len - i;
902
+ @memcpy(self.buf[0..self.buf_len], b[i..]);
892
903
  }
893
904
  }
894
905
 
@@ -901,7 +912,10 @@ pub const AsconCxof128 = struct {
901
912
  /// After first call, no more data can be absorbed with update().
902
913
  pub fn squeeze(self: *AsconCxof128, out: []u8) void {
903
914
  if (!self.squeezed) {
904
- // First squeeze - apply final permutation
915
+ var padded: [block_length]u8 = @splat(0);
916
+ @memcpy(padded[0..self.buf_len], self.buf[0..self.buf_len]);
917
+ padded[self.buf_len] = 0x01;
918
+ self.st.addBytes(&padded);
905
919
  self.st.permuteR(12);
906
920
  self.squeezed = true;
907
921
  }
@@ -1267,6 +1281,34 @@ test "Ascon-XOF128 official test vectors" {
1267
1281
  }
1268
1282
  }
1269
1283
 
1284
+ test "Ascon-XOF128/CXOF128 streaming chunking invariance" {
1285
+ const msg = "Hello, World!";
1286
+
1287
+ // XOF128: one-shot vs split must match
1288
+ var out1: [32]u8 = undefined;
1289
+ var out2: [32]u8 = undefined;
1290
+ var xof1 = AsconXof128.init(.{});
1291
+ xof1.update(msg);
1292
+ xof1.squeeze(&out1);
1293
+ var xof2 = AsconXof128.init(.{});
1294
+ xof2.update("Hello, ");
1295
+ xof2.update("World!");
1296
+ xof2.squeeze(&out2);
1297
+ try testing.expectEqualSlices(u8, &out1, &out2);
1298
+
1299
+ // CXOF128: one-shot vs split must match
1300
+ var cout1: [32]u8 = undefined;
1301
+ var cout2: [32]u8 = undefined;
1302
+ var cxof1 = AsconCxof128.init(.{ .custom = "cust" });
1303
+ cxof1.update(msg);
1304
+ cxof1.squeeze(&cout1);
1305
+ var cxof2 = AsconCxof128.init(.{ .custom = "cust" });
1306
+ cxof2.update("Hello, ");
1307
+ cxof2.update("World!");
1308
+ cxof2.squeeze(&cout2);
1309
+ try testing.expectEqualSlices(u8, &cout1, &cout2);
1310
+ }
1311
+
1270
1312
  test "Ascon-CXOF128 official test vectors" {
1271
1313
 
1272
1314
  // Test vector 1: Empty message, empty customization, 64-byte output
@@ -85,6 +85,14 @@ test toDot {
85
85
  }
86
86
  }
87
87
 
88
+ test "malformed OID" {
89
+ var empty: der.Decoder = .{ .bytes = &.{ 0x06, 0x00 } };
90
+ try std.testing.expectError(error.EndOfStream, decodeDer(&empty));
91
+
92
+ var truncated: der.Decoder = .{ .bytes = &.{ 0x06, 0x02, 0x2a, 0x80 } };
93
+ try std.testing.expectError(error.InvalidEncoding, decodeDer(&truncated));
94
+ }
95
+
88
96
  const TestCase = struct {
89
97
  encoded: []const u8,
90
98
  dot_notation: []const u8,
@@ -109,7 +117,10 @@ pub const asn1_tag = asn1.Tag.init(.oid, false, .universal);
109
117
 
110
118
  pub fn decodeDer(decoder: *der.Decoder) !Oid {
111
119
  const ele = try decoder.element(asn1_tag.toExpected());
112
- return Oid{ .encoded = decoder.view(ele) };
120
+ const encoded = decoder.view(ele);
121
+ if (encoded.len == 0) return error.EndOfStream;
122
+ if (encoded[encoded.len - 1] & 0x80 != 0) return error.InvalidEncoding;
123
+ return Oid{ .encoded = encoded };
113
124
  }
114
125
 
115
126
  pub fn encodeDer(self: Oid, encoder: *der.Encoder) !void {
@@ -73,13 +73,13 @@ pub const Tag = struct {
73
73
  const tag1: FirstTag = @bitCast(try reader.takeByte());
74
74
  var number: u14 = tag1.number;
75
75
 
76
- if (tag1.number == 15) {
76
+ if (tag1.number == 31) {
77
77
  const tag2: NextTag = @bitCast(try reader.takeByte());
78
78
  number = tag2.number;
79
79
  if (tag2.continues) {
80
80
  const tag3: NextTag = @bitCast(try reader.takeByte());
81
81
  number = (number << 7) + tag3.number;
82
- if (tag3.continues) return error.InvalidLength;
82
+ if (tag3.continues) return error.EndOfStream;
83
83
  }
84
84
  }
85
85
 
@@ -183,7 +183,7 @@ pub const Element = struct {
183
183
  }
184
184
  };
185
185
 
186
- pub const DecodeError = error{ InvalidLength, EndOfStream };
186
+ pub const DecodeError = error{EndOfStream};
187
187
 
188
188
  /// Safely decode a DER/BER/CER element at `index`:
189
189
  /// - Ensures length uses shortest form
@@ -192,26 +192,35 @@ pub const Element = struct {
192
192
  pub fn decode(bytes: []const u8, index: Index) DecodeError!Element {
193
193
  var reader: std.Io.Reader = .fixed(bytes[index..]);
194
194
 
195
- const tag = try Tag.decode(&reader);
196
- const size_or_len_size = try reader.takeByte();
195
+ const tag = Tag.decode(&reader) catch |err| switch (err) {
196
+ error.ReadFailed => unreachable, // it's all fixed buffers
197
+ else => |e| return e,
198
+ };
199
+ const size_or_len_size = reader.takeByte() catch |err| switch (err) {
200
+ error.ReadFailed => unreachable, // it's all fixed buffers
201
+ else => |e| return e,
202
+ };
197
203
 
198
- var start = index + 2;
199
- var end = start + size_or_len_size;
200
- // short form between 0-127
201
- if (size_or_len_size < 128) {
202
- if (end > bytes.len) return error.InvalidLength;
203
- } else {
204
+ const len = if (size_or_len_size < 128)
205
+ // short form between 0-127
206
+ size_or_len_size
207
+ else blk: {
204
208
  // long form between 0 and std.math.maxInt(u1024)
205
209
  const len_size: u7 = @truncate(size_or_len_size);
206
- start += len_size;
207
- if (len_size > @sizeOf(Index)) return error.InvalidLength;
210
+ if (len_size > @sizeOf(Index)) return error.EndOfStream;
208
211
 
209
- const len = try reader.takeVarInt(Index, .big, len_size);
210
- if (len < 128) return error.InvalidLength; // should have used short form
212
+ const len = reader.takeVarInt(Index, .big, len_size) catch |err| switch (err) {
213
+ error.ReadFailed => unreachable, // it's all fixed buffers
214
+ else => |e| return e,
215
+ };
216
+ if (len < 128) return error.EndOfStream; // should have used short form
211
217
 
212
- end = std.math.add(Index, start, len) catch return error.InvalidLength;
213
- if (end > bytes.len) return error.InvalidLength;
214
- }
218
+ break :blk len;
219
+ };
220
+
221
+ const start = index + @as(Index, @intCast(reader.seek));
222
+ const end = std.math.add(Index, start, len) catch return error.EndOfStream;
223
+ if (end > bytes.len) return error.EndOfStream;
215
224
 
216
225
  return Element{ .tag = tag, .slice = Slice{ .start = start, .end = end } };
217
226
  }
@@ -229,6 +238,12 @@ test Element {
229
238
  .tag = Tag.universal(.sequence, true),
230
239
  .slice = Element.Slice{ .start = 3, .end = long_form.len },
231
240
  }, Element.decode(&long_form, 0));
241
+
242
+ const multi_byte_tag = [_]u8{ 0x1F, 0x20, 0x08, 0x30, 0x36, 0x3A, 0x32, 0x37, 0x3A, 0x31, 0x35 };
243
+ try std.testing.expectEqual(Element{
244
+ .tag = Tag.universal(.time_of_day, false),
245
+ .slice = Element.Slice{ .start = 3, .end = multi_byte_tag.len },
246
+ }, Element.decode(&multi_byte_tag, 0));
232
247
  }
233
248
 
234
249
  /// For decoding.
@@ -47,8 +47,7 @@ pub const hex = struct {
47
47
  }
48
48
  _ = decodeAny(bin, encoded, null) catch |err| {
49
49
  switch (err) {
50
- error.InvalidCharacter => return error.InvalidCharacter,
51
- error.InvalidPadding => return error.InvalidPadding,
50
+ error.InvalidCharacter, error.InvalidPadding => |e| return e,
52
51
  else => unreachable,
53
52
  }
54
53
  };
@@ -93,7 +92,7 @@ pub const hex = struct {
93
92
  /// The decoder will skip any characters that are in the ignore list.
94
93
  /// The ignore list must not contain any valid hexadecimal characters.
95
94
  pub fn decoderWithIgnore(ignore_chars: []const u8) error{InvalidCharacter}!DecoderWithIgnore {
96
- var ignored_chars = StaticBitSet(256).initEmpty();
95
+ var ignored_chars = StaticBitSet(256).empty;
97
96
  for (ignore_chars) |c| {
98
97
  switch (c) {
99
98
  '0'...'9', 'a'...'f', 'A'...'F' => return error.InvalidCharacter,
@@ -228,8 +227,7 @@ pub const base64 = struct {
228
227
  pub fn decode(bin: []u8, encoded: []const u8, comptime variant: Variant) error{ InvalidCharacter, InvalidPadding }![]const u8 {
229
228
  return decodeAny(bin, encoded, variant, null) catch |err| {
230
229
  switch (err) {
231
- error.InvalidCharacter => return error.InvalidCharacter,
232
- error.InvalidPadding => return error.InvalidPadding,
230
+ error.InvalidCharacter, error.InvalidPadding => |e| return e,
233
231
  else => unreachable,
234
232
  }
235
233
  };
@@ -269,7 +267,7 @@ pub const base64 = struct {
269
267
 
270
268
  /// Creates a new decoder that ignores certain characters.
271
269
  pub fn decoderWithIgnore(ignore_chars: []const u8) error{InvalidCharacter}!DecoderWithIgnore {
272
- var ignored_chars = StaticBitSet(256).initEmpty();
270
+ var ignored_chars = StaticBitSet(256).empty;
273
271
  for (ignore_chars) |c| {
274
272
  switch (c) {
275
273
  'A'...'Z', 'a'...'z', '0'...'9' => return error.InvalidCharacter,
@@ -304,7 +302,7 @@ pub const base64 = struct {
304
302
  return (lt(x, 26) & (x +% 'A')) |
305
303
  (ge(x, 26) & lt(x, 52) & (x +% 'a' -% 26)) |
306
304
  (ge(x, 52) & lt(x, 62) & (x +% '0' -% 52)) |
307
- (eq(x, 62) & '+') | (eq(x, 63) & if (urlsafe) '_' else '/');
305
+ (eq(x, 62) & if (urlsafe) '-' else '+') | (eq(x, 63) & if (urlsafe) '_' else '/');
308
306
  }
309
307
 
310
308
  fn byteFromChar(c: u8, comptime urlsafe: bool) u8 {
@@ -312,7 +310,7 @@ pub const base64 = struct {
312
310
  (ge(c, 'A') & le(c, 'Z') & (c -% 'A')) |
313
311
  (ge(c, 'a') & le(c, 'z') & (c -% 'a' +% 26)) |
314
312
  (ge(c, '0') & le(c, '9') & (c -% '0' +% 52)) |
315
- (eq(c, '+') & 62) | (eq(c, if (urlsafe) '_' else '/') & 63);
313
+ (eq(c, if (urlsafe) '-' else '+') & 62) | (eq(c, if (urlsafe) '_' else '/') & 63);
316
314
  return x | (eq(x, 0) & ~eq(c, 'A'));
317
315
  }
318
316
 
@@ -453,6 +451,16 @@ test "hex with ignored chars" {
453
451
  try testing.expectEqualSlices(u8, &expected, bin);
454
452
  }
455
453
 
454
+ test "base64 urlsafe" {
455
+ const input = [_]u8{ 0xfb, 0xff };
456
+ var enc_buf: [4]u8 = undefined;
457
+ var dec_buf: [2]u8 = undefined;
458
+ const encoded = try base64.encode(&enc_buf, &input, .urlsafe);
459
+ try testing.expectEqualSlices(u8, "-_8=", encoded);
460
+ const decoded = try base64.decode(&dec_buf, encoded, .urlsafe);
461
+ try testing.expectEqualSlices(u8, &input, decoded);
462
+ }
463
+
456
464
  test "base64 with ignored chars" {
457
465
  const encoded = "dGVzdCBi\r\nYXNlNjQ=\n";
458
466
  const expected = "test base64";
@@ -1725,15 +1725,8 @@ const NistDRBG = struct {
1725
1725
  v: [16]u8,
1726
1726
 
1727
1727
  fn incV(g: *NistDRBG) void {
1728
- var j: usize = 15;
1729
- while (j >= 0) : (j -= 1) {
1730
- if (g.v[j] == 255) {
1731
- g.v[j] = 0;
1732
- } else {
1733
- g.v[j] += 1;
1734
- break;
1735
- }
1736
- }
1728
+ const val = std.mem.readInt(u128, &g.v, .big);
1729
+ std.mem.writeInt(u128, &g.v, val +% 1, .big);
1737
1730
  }
1738
1731
 
1739
1732
  // AES256_CTR_DRBG_Update(pd, &g.key, &g.v).
@@ -353,7 +353,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
353
353
  if (record_len > tls.max_ciphertext_len) return error.TlsRecordOverflow;
354
354
  const record_buffer = input.take(record_len) catch |err| switch (err) {
355
355
  error.EndOfStream => return error.TlsConnectionTruncated,
356
- error.ReadFailed => return error.ReadFailed,
356
+ error.ReadFailed => |e| return e,
357
357
  };
358
358
  var record_decoder: tls.Decoder = .fromTheirSlice(record_buffer);
359
359
  var ctd, const ct = content: switch (cipher_state) {
@@ -382,7 +382,9 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
382
382
  P.AEAD.decrypt(cleartext, ciphertext, auth_tag, record_header, nonce, pv.server_handshake_key) catch
383
383
  return error.TlsBadRecordMac;
384
384
  // TODO use scalar, non-slice version
385
- cleartext_fragment_end += mem.trimEnd(u8, cleartext, "\x00").len;
385
+ const trimmed_len = mem.trimEnd(u8, cleartext, "\x00").len;
386
+ if (trimmed_len == 0) return error.TlsDecodeError;
387
+ cleartext_fragment_end += trimmed_len;
386
388
  },
387
389
  }
388
390
  read_seq += 1;
@@ -1155,7 +1157,7 @@ fn readIndirect(c: *Client) Reader.Error!usize {
1155
1157
  return failRead(c, error.TlsConnectionTruncated);
1156
1158
  }
1157
1159
  },
1158
- error.ReadFailed => return error.ReadFailed,
1160
+ error.ReadFailed => |e| return e,
1159
1161
  };
1160
1162
  const ct: tls.ContentType = @enumFromInt(record_header[0]);
1161
1163
  const legacy_version = mem.readInt(u16, record_header[1..][0..2], .big);
@@ -1166,7 +1168,7 @@ fn readIndirect(c: *Client) Reader.Error!usize {
1166
1168
  if (record_end > input.buffered().len) {
1167
1169
  input.fillMore() catch |err| switch (err) {
1168
1170
  error.EndOfStream => return failRead(c, error.TlsConnectionTruncated),
1169
- error.ReadFailed => return error.ReadFailed,
1171
+ error.ReadFailed => |e| return e,
1170
1172
  };
1171
1173
  if (record_end > input.buffered().len) return 0;
1172
1174
  }
@@ -1176,6 +1178,7 @@ fn readIndirect(c: *Client) Reader.Error!usize {
1176
1178
  .tls_1_3 => {
1177
1179
  const pv = &p.tls_1_3;
1178
1180
  const P = @TypeOf(p.*);
1181
+ if (record_len < P.AEAD.tag_length) return failRead(c, error.TlsRecordOverflow);
1179
1182
  const ad = input.take(tls.record_header_len) catch unreachable; // already peeked
1180
1183
  const ciphertext_len = record_len - P.AEAD.tag_length;
1181
1184
  const ciphertext = input.take(ciphertext_len) catch unreachable; // already peeked
@@ -1192,6 +1195,7 @@ fn readIndirect(c: *Client) Reader.Error!usize {
1192
1195
  return failRead(c, error.TlsBadRecordMac);
1193
1196
  // TODO use scalar, non-slice version
1194
1197
  const msg = mem.trimEnd(u8, cleartext, "\x00");
1198
+ if (msg.len == 0) return failRead(c, error.TlsDecodeError);
1195
1199
  break :cleartext .{ msg.len - 1, @enumFromInt(msg[msg.len - 1]) };
1196
1200
  },
1197
1201
  .tls_1_2 => {
@@ -1668,3 +1672,74 @@ else
1668
1672
  .AES_256_GCM_SHA384,
1669
1673
  .ECDHE_RSA_WITH_AES_256_GCM_SHA384,
1670
1674
  });
1675
+
1676
+ fn testReadError(input_buf: []const u8, cipher: tls.ApplicationCipher) ReadError {
1677
+ var input_reader: Reader = .fixed(input_buf);
1678
+ var read_buf: [tls.max_ciphertext_record_len]u8 = undefined;
1679
+ var c: Client = .{
1680
+ .input = &input_reader,
1681
+ .reader = .{
1682
+ .buffer = &read_buf,
1683
+ .vtable = &.{ .stream = stream, .readVec = readVec },
1684
+ .seek = 0,
1685
+ .end = 0,
1686
+ },
1687
+ .output = undefined,
1688
+ .writer = undefined,
1689
+ .tls_version = .tls_1_3,
1690
+ .read_seq = 0,
1691
+ .write_seq = 0,
1692
+ .received_close_notify = false,
1693
+ .allow_truncation_attacks = false,
1694
+ .application_cipher = cipher,
1695
+ .ssl_key_log = null,
1696
+ };
1697
+ var w: Writer = .failing;
1698
+ std.testing.expectError(error.ReadFailed, c.reader.stream(&w, .unlimited)) catch
1699
+ @panic("expected ReadFailed");
1700
+ return c.read_err.?;
1701
+ }
1702
+
1703
+ test "empty inner plaintext" {
1704
+ const AEAD = crypto.aead.chacha_poly.ChaCha20Poly1305;
1705
+ const key: [AEAD.key_length]u8 = @splat(0);
1706
+ const iv: [AEAD.nonce_length]u8 = @splat(0);
1707
+
1708
+ const plaintext = [1]u8{0x00};
1709
+ var ciphertext: [plaintext.len]u8 = undefined;
1710
+ var tag: [AEAD.tag_length]u8 = undefined;
1711
+ const content_len: u16 = plaintext.len + AEAD.tag_length;
1712
+ const record_header = [_]u8{ 0x17, 0x03, 0x03 } ++ mem.toBytes(big(content_len));
1713
+ AEAD.encrypt(&ciphertext, &tag, &plaintext, &record_header, iv, key);
1714
+
1715
+ try std.testing.expectEqual(error.TlsDecodeError, testReadError(
1716
+ &record_header ++ ciphertext ++ tag,
1717
+ .{ .CHACHA20_POLY1305_SHA256 = .{ .tls_1_3 = .{
1718
+ .server_key = key,
1719
+ .server_iv = iv,
1720
+ .client_secret = undefined,
1721
+ .server_secret = undefined,
1722
+ .client_key = undefined,
1723
+ .client_iv = undefined,
1724
+ } } },
1725
+ ));
1726
+ }
1727
+
1728
+ test "record shorter than tag" {
1729
+ const AEAD = crypto.aead.chacha_poly.ChaCha20Poly1305;
1730
+ const record_len: u16 = AEAD.tag_length - 1;
1731
+ const header = [_]u8{ 0x17, 0x03, 0x03 } ++ mem.toBytes(big(record_len));
1732
+ const wire = header ++ @as([record_len]u8, @splat(0));
1733
+
1734
+ try std.testing.expectEqual(error.TlsRecordOverflow, testReadError(
1735
+ &wire,
1736
+ .{ .CHACHA20_POLY1305_SHA256 = .{ .tls_1_3 = .{
1737
+ .server_key = undefined,
1738
+ .server_iv = undefined,
1739
+ .client_secret = undefined,
1740
+ .server_secret = undefined,
1741
+ .client_key = undefined,
1742
+ .client_iv = undefined,
1743
+ } } },
1744
+ ));
1745
+ }
@@ -666,7 +666,7 @@ pub const Decoder = struct {
666
666
  if (request_amt > dest.len) return error.TlsRecordOverflow;
667
667
  stream.readSlice(dest[0..request_amt]) catch |err| switch (err) {
668
668
  error.EndOfStream => return error.TlsConnectionTruncated,
669
- error.ReadFailed => return error.ReadFailed,
669
+ error.ReadFailed => |e| return e,
670
670
  };
671
671
  d.cap += request_amt;
672
672
  }
package/std/crypto.zig CHANGED
@@ -367,6 +367,7 @@ test {
367
367
  _ = ff;
368
368
  _ = errors;
369
369
  _ = tls;
370
+ _ = tls.Client;
370
371
  _ = Certificate;
371
372
  _ = codecs;
372
373
  }
@@ -22,7 +22,9 @@ const cast = std.math.cast;
22
22
  const maxInt = std.math.maxInt;
23
23
  const ArrayList = std.ArrayList;
24
24
  const Endian = std.builtin.Endian;
25
- const Reader = std.Io.Reader;
25
+ const Io = std.Io;
26
+ const Reader = Io.Reader;
27
+ const Error = std.debug.SelfInfoError;
26
28
 
27
29
  const Dwarf = @This();
28
30
 
@@ -1218,6 +1220,7 @@ pub fn populateSrcLocCache(d: *Dwarf, gpa: Allocator, endian: Endian, cu: *Compi
1218
1220
  pub fn getLineNumberInfo(
1219
1221
  d: *Dwarf,
1220
1222
  gpa: Allocator,
1223
+ text_arena: Allocator,
1221
1224
  endian: Endian,
1222
1225
  compile_unit: *CompileUnit,
1223
1226
  target_address: u64,
@@ -1230,7 +1233,7 @@ pub fn getLineNumberInfo(
1230
1233
  const file_entry = &slc.files[file_index];
1231
1234
  if (file_entry.dir_index >= slc.directories.len) return bad();
1232
1235
  const dir_name = slc.directories[file_entry.dir_index].path;
1233
- const file_name = try std.fs.path.join(gpa, &.{ dir_name, file_entry.path });
1236
+ const file_name = try std.fs.path.join(text_arena, &.{ dir_name, file_entry.path });
1234
1237
  return .{
1235
1238
  .line = entry.line,
1236
1239
  .column = entry.column,
@@ -1543,21 +1546,38 @@ fn getStringGeneric(opt_str: ?[]const u8, offset: u64) ![:0]const u8 {
1543
1546
  return str[casted_offset..last :0];
1544
1547
  }
1545
1548
 
1546
- pub fn getSymbol(di: *Dwarf, gpa: Allocator, endian: Endian, address: u64) !std.debug.Symbol {
1549
+ pub fn getSymbols(
1550
+ di: *Dwarf,
1551
+ symbol_allocator: Allocator,
1552
+ text_arena: Allocator,
1553
+ endian: Endian,
1554
+ address: u64,
1555
+ resolve_inline_callers: bool,
1556
+ symbols: *std.ArrayList(std.debug.Symbol),
1557
+ ) std.debug.SelfInfoError!void {
1558
+ _ = resolve_inline_callers;
1559
+ const gpa = std.debug.getDebugInfoAllocator();
1560
+
1547
1561
  const compile_unit = di.findCompileUnit(endian, address) catch |err| switch (err) {
1548
- error.MissingDebugInfo, error.InvalidDebugInfo => return .unknown,
1549
- else => return err,
1562
+ error.EndOfStream => return error.MissingDebugInfo,
1563
+ error.Overflow => return error.InvalidDebugInfo,
1564
+ error.ReadFailed, error.InvalidDebugInfo, error.MissingDebugInfo => |e| return e,
1550
1565
  };
1551
- return .{
1566
+ try symbols.append(symbol_allocator, .{
1552
1567
  .name = di.getSymbolName(address),
1553
1568
  .compile_unit_name = compile_unit.die.getAttrString(di, endian, std.dwarf.AT.name, di.section(.debug_str), compile_unit) catch |err| switch (err) {
1554
1569
  error.MissingDebugInfo, error.InvalidDebugInfo => null,
1555
1570
  },
1556
- .source_location = di.getLineNumberInfo(gpa, endian, compile_unit, address) catch |err| switch (err) {
1571
+ .source_location = di.getLineNumberInfo(gpa, text_arena, endian, compile_unit, address) catch |err| switch (err) {
1557
1572
  error.MissingDebugInfo, error.InvalidDebugInfo => null,
1558
- else => return err,
1573
+ error.ReadFailed,
1574
+ error.EndOfStream,
1575
+ error.Overflow,
1576
+ error.StreamTooLong,
1577
+ => return error.InvalidDebugInfo,
1578
+ else => |e| return e,
1559
1579
  },
1560
- };
1580
+ });
1561
1581
  }
1562
1582
 
1563
1583
  /// DWARF5 7.4: "In the 32-bit DWARF format, all values that represent lengths of DWARF sections and
@@ -99,6 +99,10 @@ pub fn resolveAddresses(
99
99
  // due to split debug information. For now, we'll just resolve the addreses one by one.
100
100
  for (sorted_pc_addrs, output) |pc_addr, *src_loc| {
101
101
  const dwarf, const dwarf_pc_addr = mf.getDwarfForAddress(gpa, io, pc_addr) catch |err| switch (err) {
102
+ error.MissingDebugInfo => {
103
+ src_loc.* = .invalid;
104
+ continue;
105
+ },
102
106
  error.InvalidMachO, error.InvalidDwarf => return error.InvalidDebugInfo,
103
107
  else => |e| return e,
104
108
  };