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

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 (242) hide show
  1. package/LICENSE +19 -0
  2. package/c/math.zig +135 -35
  3. package/c/stropts.zig +17 -0
  4. package/c.zig +1 -0
  5. package/compiler/aro/aro/Attribute/names.zig +604 -589
  6. package/compiler/aro/aro/Attribute.zig +202 -116
  7. package/compiler/aro/aro/Builtins/common.zig +874 -863
  8. package/compiler/aro/aro/Builtins/eval.zig +15 -7
  9. package/compiler/aro/aro/Builtins.zig +0 -1
  10. package/compiler/aro/aro/CodeGen.zig +3 -1
  11. package/compiler/aro/aro/Compilation.zig +120 -97
  12. package/compiler/aro/aro/Diagnostics.zig +21 -17
  13. package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
  14. package/compiler/aro/aro/Driver.zig +124 -50
  15. package/compiler/aro/aro/LangOpts.zig +12 -2
  16. package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
  17. package/compiler/aro/aro/Parser.zig +336 -142
  18. package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
  19. package/compiler/aro/aro/Preprocessor.zig +127 -56
  20. package/compiler/aro/aro/Target.zig +17 -12
  21. package/compiler/aro/aro/Tokenizer.zig +31 -14
  22. package/compiler/aro/aro/Toolchain.zig +4 -7
  23. package/compiler/aro/aro/Tree.zig +178 -148
  24. package/compiler/aro/aro/TypeStore.zig +82 -24
  25. package/compiler/aro/aro/Value.zig +13 -17
  26. package/compiler/aro/aro/features.zig +1 -0
  27. package/compiler/aro/aro/pragmas/once.zig +0 -1
  28. package/compiler/aro/aro/record_layout.zig +3 -3
  29. package/compiler/aro/assembly_backend/x86_64.zig +3 -4
  30. package/compiler/aro/backend/Assembly.zig +1 -2
  31. package/compiler/aro/backend/Interner.zig +2 -2
  32. package/compiler/aro/backend/Ir.zig +100 -92
  33. package/compiler/aro/include/ptrcheck.h +49 -0
  34. package/compiler/aro/main.zig +26 -10
  35. package/compiler/build_runner.zig +1 -0
  36. package/compiler/objdump.zig +93 -0
  37. package/compiler/reduce.zig +5 -1
  38. package/compiler/resinator/compile.zig +2 -2
  39. package/compiler/resinator/main.zig +7 -1
  40. package/compiler/resinator/preprocess.zig +1 -3
  41. package/compiler/std-docs.zig +8 -1
  42. package/compiler/test_runner.zig +193 -61
  43. package/compiler/translate-c/MacroTranslator.zig +80 -11
  44. package/compiler/translate-c/PatternList.zig +1 -9
  45. package/compiler/translate-c/Scope.zig +43 -6
  46. package/compiler/translate-c/Translator.zig +364 -126
  47. package/compiler/translate-c/ast.zig +19 -11
  48. package/compiler/translate-c/main.zig +75 -16
  49. package/compiler_rt/cos.zig +141 -52
  50. package/compiler_rt/limb64.zig +266 -0
  51. package/compiler_rt/long_double.zig +37 -0
  52. package/compiler_rt/mulo.zig +6 -1
  53. package/compiler_rt/rem_pio2l.zig +173 -0
  54. package/compiler_rt/sin.zig +140 -55
  55. package/compiler_rt/sincos.zig +279 -72
  56. package/compiler_rt/tan.zig +118 -47
  57. package/compiler_rt/trig.zig +256 -6
  58. package/compiler_rt.zig +2 -0
  59. package/fuzzer.zig +855 -307
  60. package/libc/musl/src/math/pow.c +343 -0
  61. package/package.json +1 -1
  62. package/std/Build/Fuzz.zig +6 -19
  63. package/std/Build/Module.zig +1 -1
  64. package/std/Build/Step/CheckObject.zig +3 -3
  65. package/std/Build/Step/Compile.zig +18 -0
  66. package/std/Build/Step/ConfigHeader.zig +49 -33
  67. package/std/Build/Step/InstallArtifact.zig +18 -0
  68. package/std/Build/Step/Run.zig +536 -87
  69. package/std/Build/Step/TranslateC.zig +0 -6
  70. package/std/Build/Step.zig +8 -15
  71. package/std/Build/WebServer.zig +29 -17
  72. package/std/Build/abi.zig +47 -11
  73. package/std/Build.zig +17 -14
  74. package/std/Io/Dispatch.zig +2 -0
  75. package/std/Io/File/Reader.zig +3 -1
  76. package/std/Io/File.zig +1 -0
  77. package/std/Io/Kqueue.zig +2 -2
  78. package/std/Io/Threaded.zig +181 -143
  79. package/std/Io/Uring.zig +2 -1
  80. package/std/Io.zig +970 -2
  81. package/std/Target.zig +3 -2
  82. package/std/Thread.zig +8 -3
  83. package/std/array_hash_map.zig +96 -555
  84. package/std/array_list.zig +22 -31
  85. package/std/bit_set.zig +22 -6
  86. package/std/builtin/assembly.zig +68 -0
  87. package/std/c.zig +17 -17
  88. package/std/compress/flate/Compress.zig +3 -3
  89. package/std/crypto/Certificate/Bundle.zig +15 -1
  90. package/std/crypto/codecs/asn1.zig +33 -18
  91. package/std/crypto/codecs/base64_hex_ct.zig +14 -4
  92. package/std/debug/Dwarf.zig +29 -9
  93. package/std/debug/Info.zig +4 -0
  94. package/std/debug/MachOFile.zig +46 -8
  95. package/std/debug/Pdb.zig +539 -36
  96. package/std/debug/SelfInfo/Elf.zig +19 -18
  97. package/std/debug/SelfInfo/MachO.zig +18 -7
  98. package/std/debug/SelfInfo/Windows.zig +138 -36
  99. package/std/debug.zig +179 -65
  100. package/std/enums.zig +25 -19
  101. package/std/heap/ArenaAllocator.zig +145 -154
  102. package/std/heap/debug_allocator.zig +7 -7
  103. package/std/http/Client.zig +10 -6
  104. package/std/http.zig +11 -9
  105. package/std/json/Stringify.zig +3 -3
  106. package/std/json/dynamic.zig +4 -4
  107. package/std/math/big/int.zig +16 -17
  108. package/std/mem/Allocator.zig +4 -5
  109. package/std/mem.zig +48 -0
  110. package/std/os/emscripten.zig +2 -18
  111. package/std/os/linux/arc.zig +144 -0
  112. package/std/os/linux.zig +21 -4
  113. package/std/os/windows.zig +2 -2
  114. package/std/pdb.zig +143 -4
  115. package/std/posix.zig +6 -12
  116. package/std/priority_dequeue.zig +13 -12
  117. package/std/priority_queue.zig +5 -4
  118. package/std/process/Child.zig +1 -1
  119. package/std/process/Environ.zig +1 -1
  120. package/std/start.zig +17 -4
  121. package/std/std.zig +19 -6
  122. package/std/testing/FailingAllocator.zig +4 -4
  123. package/std/testing/Smith.zig +37 -2
  124. package/std/zig/Ast/Render.zig +186 -458
  125. package/std/zig/Ast.zig +0 -4
  126. package/std/zig/AstGen.zig +44 -7
  127. package/std/zig/AstSmith.zig +2602 -0
  128. package/std/zig/Client.zig +8 -3
  129. package/std/zig/Parse.zig +83 -74
  130. package/std/zig/Server.zig +26 -0
  131. package/std/zig/Zir.zig +17 -0
  132. package/std/zig/c_translation/helpers.zig +14 -9
  133. package/std/zig/llvm/Builder.zig +107 -48
  134. package/std/zig/system.zig +20 -4
  135. package/std/zig/tokenizer.zig +2 -1
  136. package/std/zig.zig +6 -0
  137. package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
  138. package/libc/mingw/complex/cabs.c +0 -48
  139. package/libc/mingw/complex/cabsf.c +0 -48
  140. package/libc/mingw/complex/cacos.c +0 -50
  141. package/libc/mingw/complex/cacosf.c +0 -50
  142. package/libc/mingw/complex/carg.c +0 -48
  143. package/libc/mingw/complex/cargf.c +0 -48
  144. package/libc/mingw/complex/casin.c +0 -50
  145. package/libc/mingw/complex/casinf.c +0 -50
  146. package/libc/mingw/complex/catan.c +0 -50
  147. package/libc/mingw/complex/catanf.c +0 -50
  148. package/libc/mingw/complex/ccos.c +0 -50
  149. package/libc/mingw/complex/ccosf.c +0 -50
  150. package/libc/mingw/complex/cexp.c +0 -48
  151. package/libc/mingw/complex/cexpf.c +0 -48
  152. package/libc/mingw/complex/cimag.c +0 -48
  153. package/libc/mingw/complex/cimagf.c +0 -48
  154. package/libc/mingw/complex/clog.c +0 -48
  155. package/libc/mingw/complex/clog10.c +0 -49
  156. package/libc/mingw/complex/clog10f.c +0 -49
  157. package/libc/mingw/complex/clogf.c +0 -48
  158. package/libc/mingw/complex/conj.c +0 -48
  159. package/libc/mingw/complex/conjf.c +0 -48
  160. package/libc/mingw/complex/cpow.c +0 -48
  161. package/libc/mingw/complex/cpowf.c +0 -48
  162. package/libc/mingw/complex/cproj.c +0 -48
  163. package/libc/mingw/complex/cprojf.c +0 -48
  164. package/libc/mingw/complex/creal.c +0 -48
  165. package/libc/mingw/complex/crealf.c +0 -48
  166. package/libc/mingw/complex/csin.c +0 -50
  167. package/libc/mingw/complex/csinf.c +0 -50
  168. package/libc/mingw/complex/csqrt.c +0 -48
  169. package/libc/mingw/complex/csqrtf.c +0 -48
  170. package/libc/mingw/complex/ctan.c +0 -50
  171. package/libc/mingw/complex/ctanf.c +0 -50
  172. package/libc/mingw/math/arm/s_rint.c +0 -86
  173. package/libc/mingw/math/arm/s_rintf.c +0 -51
  174. package/libc/mingw/math/arm/sincos.S +0 -30
  175. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  176. package/libc/mingw/math/arm64/rint.c +0 -12
  177. package/libc/mingw/math/arm64/rintf.c +0 -12
  178. package/libc/mingw/math/arm64/sincos.S +0 -32
  179. package/libc/mingw/math/bsd_private_base.h +0 -148
  180. package/libc/mingw/math/frexpf.c +0 -13
  181. package/libc/mingw/math/frexpl.c +0 -71
  182. package/libc/mingw/math/x86/acosf.c +0 -29
  183. package/libc/mingw/math/x86/atanf.c +0 -23
  184. package/libc/mingw/math/x86/atanl.c +0 -18
  185. package/libc/mingw/math/x86/cos.def.h +0 -65
  186. package/libc/mingw/math/x86/cosl.c +0 -46
  187. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  188. package/libc/mingw/math/x86/ldexp.c +0 -23
  189. package/libc/mingw/math/x86/scalbn.S +0 -41
  190. package/libc/mingw/math/x86/scalbnf.S +0 -40
  191. package/libc/mingw/math/x86/sin.def.h +0 -65
  192. package/libc/mingw/math/x86/sinl.c +0 -46
  193. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  194. package/libc/mingw/math/x86/tanl.S +0 -62
  195. package/libc/mingw/misc/btowc.c +0 -28
  196. package/libc/mingw/misc/wcstof.c +0 -66
  197. package/libc/mingw/misc/wcstoimax.c +0 -132
  198. package/libc/mingw/misc/wcstoumax.c +0 -126
  199. package/libc/mingw/misc/wctob.c +0 -29
  200. package/libc/mingw/misc/winbs_uint64.c +0 -6
  201. package/libc/mingw/misc/winbs_ulong.c +0 -6
  202. package/libc/mingw/misc/winbs_ushort.c +0 -6
  203. package/libc/mingw/stdio/_Exit.c +0 -10
  204. package/libc/mingw/stdio/_findfirst64i32.c +0 -21
  205. package/libc/mingw/stdio/_findnext64i32.c +0 -21
  206. package/libc/mingw/stdio/_fstat64i32.c +0 -37
  207. package/libc/mingw/stdio/_stat64i32.c +0 -37
  208. package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
  209. package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
  210. package/libc/mingw/stdio/_wstat64i32.c +0 -37
  211. package/libc/musl/src/legacy/isastream.c +0 -7
  212. package/libc/musl/src/legacy/valloc.c +0 -8
  213. package/libc/musl/src/math/__cosl.c +0 -96
  214. package/libc/musl/src/math/__sinl.c +0 -78
  215. package/libc/musl/src/math/__tanl.c +0 -143
  216. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  217. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  218. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  219. package/libc/musl/src/math/cosl.c +0 -39
  220. package/libc/musl/src/math/fdim.c +0 -10
  221. package/libc/musl/src/math/finite.c +0 -7
  222. package/libc/musl/src/math/finitef.c +0 -7
  223. package/libc/musl/src/math/frexp.c +0 -23
  224. package/libc/musl/src/math/frexpf.c +0 -23
  225. package/libc/musl/src/math/frexpl.c +0 -29
  226. package/libc/musl/src/math/i386/lrint.c +0 -8
  227. package/libc/musl/src/math/i386/lrintf.c +0 -8
  228. package/libc/musl/src/math/i386/rintf.c +0 -7
  229. package/libc/musl/src/math/lrint.c +0 -72
  230. package/libc/musl/src/math/lrintf.c +0 -8
  231. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  232. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  233. package/libc/musl/src/math/rintf.c +0 -30
  234. package/libc/musl/src/math/s390x/rintf.c +0 -15
  235. package/libc/musl/src/math/sincosl.c +0 -60
  236. package/libc/musl/src/math/sinl.c +0 -41
  237. package/libc/musl/src/math/tanl.c +0 -29
  238. package/libc/musl/src/math/x32/lrint.s +0 -5
  239. package/libc/musl/src/math/x32/lrintf.s +0 -5
  240. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  241. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
  242. package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
@@ -628,12 +628,12 @@ pub const Mutable = struct {
628
628
 
629
629
  // Slice of the upper bits if they exist, these will be ignored and allows us to use addCarry to determine
630
630
  // if an overflow occurred.
631
- const x = Const{
631
+ const x: Const = .{
632
632
  .positive = a.positive,
633
633
  .limbs = a.limbs[0..@min(req_limbs, a.limbs.len)],
634
634
  };
635
635
 
636
- const y = Const{
636
+ const y: Const = .{
637
637
  .positive = b.positive,
638
638
  .limbs = b.limbs[0..@min(req_limbs, b.limbs.len)],
639
639
  };
@@ -647,9 +647,8 @@ pub const Mutable = struct {
647
647
  // Note: after this we still might need to wrap.
648
648
  const msl = @max(a.limbs.len, b.limbs.len);
649
649
  if (msl < req_limbs) {
650
+ r.len = msl + 1;
650
651
  r.limbs[msl] = 1;
651
- r.len = req_limbs;
652
- @memset(r.limbs[msl + 1 .. req_limbs], 0);
653
652
  } else {
654
653
  carry_truncated = true;
655
654
  }
@@ -673,12 +672,12 @@ pub const Mutable = struct {
673
672
 
674
673
  // Slice of the upper bits if they exist, these will be ignored and allows us to use addCarry to determine
675
674
  // if an overflow occurred.
676
- const x = Const{
675
+ const x: Const = .{
677
676
  .positive = a.positive,
678
677
  .limbs = a.limbs[0..@min(req_limbs, a.limbs.len)],
679
678
  };
680
679
 
681
- const y = Const{
680
+ const y: Const = .{
682
681
  .positive = b.positive,
683
682
  .limbs = b.limbs[0..@min(req_limbs, b.limbs.len)],
684
683
  };
@@ -690,12 +689,12 @@ pub const Mutable = struct {
690
689
  // Note: In this case, might _also_ need to saturate.
691
690
  const msl = @max(a.limbs.len, b.limbs.len);
692
691
  if (msl < req_limbs) {
692
+ r.len = msl + 1;
693
693
  r.limbs[msl] = 1;
694
- r.len = req_limbs;
695
694
  // Note: Saturation may still be required if msl == req_limbs - 1
696
695
  } else {
697
696
  // Overflowed req_limbs, definitely saturate.
698
- r.setTwosCompIntLimit(if (r.positive) .max else .min, signedness, bit_count);
697
+ return r.setTwosCompIntLimit(if (r.positive) .max else .min, signedness, bit_count);
699
698
  }
700
699
  }
701
700
 
@@ -1374,7 +1373,7 @@ pub const Mutable = struct {
1374
1373
  /// r is `calcTwosCompLimbCount(bit_count)`.
1375
1374
  pub fn bitNotWrap(r: *Mutable, a: Const, signedness: Signedness, bit_count: usize) void {
1376
1375
  r.copy(a.negate());
1377
- const negative_one = Const{ .limbs = &.{1}, .positive = false };
1376
+ const negative_one: Const = .{ .limbs = &.{1}, .positive = false };
1378
1377
  _ = r.addWrap(r.toConst(), negative_one, signedness, bit_count);
1379
1378
  }
1380
1379
 
@@ -1740,13 +1739,13 @@ pub const Mutable = struct {
1740
1739
  r.positive = r_positive;
1741
1740
  } else {
1742
1741
  // Shrink x, y such that the trailing zero limbs shared between are removed.
1743
- var x0 = Mutable{
1742
+ var x0: Mutable = .{
1744
1743
  .limbs = x.limbs[xy_trailing..],
1745
1744
  .len = x.len - xy_trailing,
1746
1745
  .positive = true,
1747
1746
  };
1748
1747
 
1749
- var y0 = Mutable{
1748
+ var y0: Mutable = .{
1750
1749
  .limbs = y.limbs[xy_trailing..],
1751
1750
  .len = y.len - xy_trailing,
1752
1751
  .positive = true,
@@ -1809,7 +1808,7 @@ pub const Mutable = struct {
1809
1808
  // x >= y * b^(n - t) can be replaced by x/b^(n - t) >= y.
1810
1809
 
1811
1810
  // 'divide' x by b^(n - t)
1812
- var tmp = Mutable{
1811
+ var tmp: Mutable = .{
1813
1812
  .limbs = x.limbs[shift..],
1814
1813
  .len = x.len - shift,
1815
1814
  .positive = true,
@@ -2108,7 +2107,7 @@ pub const Const = struct {
2108
2107
  pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed {
2109
2108
  const limbs = try allocator.alloc(Limb, @max(Managed.default_capacity, self.limbs.len));
2110
2109
  @memcpy(limbs[0..self.limbs.len], self.limbs);
2111
- return Managed{
2110
+ return .{
2112
2111
  .allocator = allocator,
2113
2112
  .limbs = limbs,
2114
2113
  .metadata = if (self.positive)
@@ -2802,7 +2801,7 @@ pub const Managed = struct {
2802
2801
  /// default capacity will be used instead.
2803
2802
  /// The integer value after initializing is `0`.
2804
2803
  pub fn initCapacity(allocator: Allocator, capacity: usize) !Managed {
2805
- return Managed{
2804
+ return .{
2806
2805
  .allocator = allocator,
2807
2806
  .metadata = 1,
2808
2807
  .limbs = block: {
@@ -2868,7 +2867,7 @@ pub const Managed = struct {
2868
2867
  }
2869
2868
 
2870
2869
  pub fn cloneWithDifferentAllocator(other: Managed, allocator: Allocator) !Managed {
2871
- return Managed{
2870
+ return .{
2872
2871
  .allocator = allocator,
2873
2872
  .metadata = other.metadata,
2874
2873
  .limbs = block: {
@@ -3454,7 +3453,7 @@ pub const Managed = struct {
3454
3453
  const tmp = try rma.allocator.alloc(Limb, a_len);
3455
3454
  defer rma.allocator.free(tmp);
3456
3455
  @memcpy(tmp[0..a_len], a.limbs[0..a_len]);
3457
- const a_const = Const{ .limbs = tmp[0..a_len], .positive = a.isPositive() };
3456
+ const a_const: Const = .{ .limbs = tmp[0..a_len], .positive = a.isPositive() };
3458
3457
  var rma_mut = rma.toMutable();
3459
3458
  rma_mut.sqrNoAlias(a_const, rma.allocator);
3460
3459
  rma.setMetadata(rma_mut.positive, rma_mut.len);
@@ -3479,7 +3478,7 @@ pub const Managed = struct {
3479
3478
  const tmp = try rma.allocator.alloc(Limb, a_len);
3480
3479
  defer rma.allocator.free(tmp);
3481
3480
  @memcpy(tmp[0..a_len], a.limbs[0..a_len]);
3482
- const a_const = Const{ .limbs = tmp[0..a_len], .positive = a.isPositive() };
3481
+ const a_const: Const = .{ .limbs = tmp[0..a_len], .positive = a.isPositive() };
3483
3482
  var rma_mut = rma.toMutable();
3484
3483
  rma_mut.pow(a_const, b, limbs_buffer);
3485
3484
  rma.setMetadata(rma_mut.positive, rma_mut.len);
@@ -322,7 +322,7 @@ pub fn resize(self: Allocator, allocation: anytype, new_len: usize) bool {
322
322
  if (allocation.len == 0) {
323
323
  return false;
324
324
  }
325
- const old_memory = mem.sliceAsBytes(allocation);
325
+ const old_memory: []u8 = @ptrCast(@constCast(mem.absorbSentinel(allocation)));
326
326
  // I would like to use saturating multiplication here, but LLVM cannot lower it
327
327
  // on WebAssembly: https://github.com/ziglang/zig/issues/9660
328
328
  //const new_len_bytes = new_len *| @sizeOf(T);
@@ -368,7 +368,7 @@ pub fn remap(self: Allocator, allocation: anytype, new_len: usize) ?@TypeOf(allo
368
368
  new_memory.len = new_len;
369
369
  return new_memory;
370
370
  }
371
- const old_memory = mem.sliceAsBytes(allocation);
371
+ const old_memory: []u8 = @ptrCast(@constCast(mem.absorbSentinel(allocation)));
372
372
  // I would like to use saturating multiplication here, but LLVM cannot lower it
373
373
  // on WebAssembly: https://github.com/ziglang/zig/issues/9660
374
374
  //const new_len_bytes = new_len *| @sizeOf(T);
@@ -420,7 +420,7 @@ pub fn reallocAdvanced(
420
420
  return ptr;
421
421
  }
422
422
 
423
- const old_byte_slice = mem.sliceAsBytes(old_mem);
423
+ const old_byte_slice: []u8 = @ptrCast(@constCast(mem.absorbSentinel(old_mem)));
424
424
  const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return error.OutOfMemory;
425
425
  // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
426
426
  if (self.rawRemap(old_byte_slice, .fromByteUnits(slice_info.alignment orelse @alignOf(T)), byte_count, return_address)) |p| {
@@ -443,8 +443,7 @@ pub fn reallocAdvanced(
443
443
  pub fn free(self: Allocator, memory: anytype) void {
444
444
  const slice_info = @typeInfo(@TypeOf(memory)).pointer;
445
445
  comptime assert(slice_info.size == .slice);
446
- const mem_with_sent = memory[0 .. memory.len + @intFromBool(slice_info.sentinel() != null)];
447
- const bytes: []u8 = @ptrCast(@constCast(mem_with_sent));
446
+ const bytes: []u8 = @ptrCast(@constCast(mem.absorbSentinel(memory)));
448
447
  if (bytes.len == 0) return;
449
448
  @memset(bytes, undefined);
450
449
  self.rawFree(bytes, .fromByteUnits(slice_info.alignment orelse @alignOf(slice_info.child)), @returnAddress());
package/std/mem.zig CHANGED
@@ -4709,6 +4709,54 @@ test "sliceAsBytes preserves pointer attributes" {
4709
4709
  try testing.expectEqual(in.alignment, out.alignment);
4710
4710
  }
4711
4711
 
4712
+ fn AbsorbSentinelReturnType(comptime Slice: type) type {
4713
+ const info = @typeInfo(Slice).pointer;
4714
+ assert(info.size == .slice);
4715
+ return @Pointer(.slice, .{
4716
+ .@"const" = info.is_const,
4717
+ .@"volatile" = info.is_volatile,
4718
+ .@"allowzero" = info.is_allowzero,
4719
+ .@"addrspace" = info.address_space,
4720
+ .@"align" = info.alignment,
4721
+ }, info.child, null);
4722
+ }
4723
+
4724
+ /// If the provided slice is not sentinel terminated, do nothing and return that slice.
4725
+ /// If it is sentinel-terminated, return a non-sentinel-terminated slice with the
4726
+ /// length increased by one to include the absorbed sentinel element.
4727
+ pub fn absorbSentinel(slice: anytype) AbsorbSentinelReturnType(@TypeOf(slice)) {
4728
+ const info = @typeInfo(@TypeOf(slice)).pointer;
4729
+ comptime assert(info.size == .slice);
4730
+ if (info.sentinel_ptr == null) {
4731
+ return slice;
4732
+ } else {
4733
+ return slice.ptr[0 .. slice.len + 1];
4734
+ }
4735
+ }
4736
+
4737
+ test absorbSentinel {
4738
+ {
4739
+ var buffer: [3:0]u8 = .{ 1, 2, 3 };
4740
+ const foo: [:0]const u8 = &buffer;
4741
+ const bar: []const u8 = &buffer;
4742
+ try testing.expectEqual([]const u8, @TypeOf(absorbSentinel(foo)));
4743
+ try testing.expectEqual([]const u8, @TypeOf(absorbSentinel(bar)));
4744
+ try testing.expectEqualSlices(u8, &.{ 1, 2, 3, 0 }, absorbSentinel(foo));
4745
+ try testing.expectEqualSlices(u8, &.{ 1, 2, 3 }, absorbSentinel(bar));
4746
+ }
4747
+ {
4748
+ var buffer: [3:0]u8 = .{ 1, 2, 3 };
4749
+ const foo: [:0]u8 = &buffer;
4750
+ const bar: []u8 = &buffer;
4751
+ try testing.expectEqual([]u8, @TypeOf(absorbSentinel(foo)));
4752
+ try testing.expectEqual([]u8, @TypeOf(absorbSentinel(bar)));
4753
+ var expected_foo = [_]u8{ 1, 2, 3, 0 };
4754
+ try testing.expectEqualSlices(u8, &expected_foo, absorbSentinel(foo));
4755
+ var expected_bar = [_]u8{ 1, 2, 3 };
4756
+ try testing.expectEqualSlices(u8, &expected_bar, absorbSentinel(bar));
4757
+ }
4758
+ }
4759
+
4712
4760
  /// Round an address down to the next (or current) aligned address.
4713
4761
  /// Unlike `alignForward`, `alignment` can be any positive number, not just a power of 2.
4714
4762
  pub fn alignForwardAnyAlign(comptime T: type, addr: T, alignment: T) T {
@@ -11,22 +11,6 @@ const c = std.c;
11
11
 
12
12
  pub const FILE = c.FILE;
13
13
 
14
- var __stack_chk_guard: usize = 0;
15
- fn __stack_chk_fail() callconv(.c) void {
16
- std.debug.print("stack smashing detected: terminated\n", .{});
17
- emscripten_force_exit(127);
18
- }
19
-
20
- comptime {
21
- if (builtin.os.tag == .emscripten) {
22
- if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) {
23
- // Emscripten does not provide these symbols, so we must export our own
24
- @export(&__stack_chk_guard, .{ .name = "__stack_chk_guard", .linkage = .strong });
25
- @export(&__stack_chk_fail, .{ .name = "__stack_chk_fail", .linkage = .strong });
26
- }
27
- }
28
- }
29
-
30
14
  pub const PF = linux.PF;
31
15
  pub const AF = linux.AF;
32
16
  pub const CLOCK = linux.CLOCK;
@@ -227,8 +211,8 @@ pub const W = struct {
227
211
  pub fn TERMSIG(s: u32) SIG {
228
212
  return @enumFromInt(s & 0x7f);
229
213
  }
230
- pub fn STOPSIG(s: u32) u32 {
231
- return EXITSTATUS(s);
214
+ pub fn STOPSIG(s: u32) SIG {
215
+ return @enumFromInt(EXITSTATUS(s));
232
216
  }
233
217
  pub fn IFEXITED(s: u32) bool {
234
218
  return (s & 0x7f) == 0;
@@ -0,0 +1,144 @@
1
+ const builtin = @import("builtin");
2
+ const std = @import("../../std.zig");
3
+ const SYS = std.os.linux.SYS;
4
+
5
+ pub fn syscall0(number: SYS) u32 {
6
+ return asm volatile ("trap_s 0"
7
+ : [ret] "={r0}" (-> u32),
8
+ : [number] "{r8}" (@intFromEnum(number)),
9
+ : .{ .memory = true });
10
+ }
11
+
12
+ pub fn syscall1(number: SYS, arg1: u32) u32 {
13
+ return asm volatile ("trap_s 0"
14
+ : [ret] "={r0}" (-> u32),
15
+ : [number] "{r8}" (@intFromEnum(number)),
16
+ [arg1] "{r0}" (arg1),
17
+ : .{ .memory = true });
18
+ }
19
+
20
+ pub fn syscall2(number: SYS, arg1: u32, arg2: u32) u32 {
21
+ return asm volatile ("trap_s 0"
22
+ : [ret] "={r0}" (-> u32),
23
+ : [number] "{r8}" (@intFromEnum(number)),
24
+ [arg1] "{r0}" (arg1),
25
+ [arg2] "{r1}" (arg2),
26
+ : .{ .memory = true });
27
+ }
28
+
29
+ pub fn syscall3(number: SYS, arg1: u32, arg2: u32, arg3: u32) u32 {
30
+ return asm volatile ("trap_s 0"
31
+ : [ret] "={r0}" (-> u32),
32
+ : [number] "{r8}" (@intFromEnum(number)),
33
+ [arg1] "{r0}" (arg1),
34
+ [arg2] "{r1}" (arg2),
35
+ [arg3] "{r2}" (arg3),
36
+ : .{ .memory = true });
37
+ }
38
+
39
+ pub fn syscall4(number: SYS, arg1: u32, arg2: u32, arg3: u32, arg4: u32) u32 {
40
+ return asm volatile ("trap_s 0"
41
+ : [ret] "={r0}" (-> u32),
42
+ : [number] "{r8}" (@intFromEnum(number)),
43
+ [arg1] "{r0}" (arg1),
44
+ [arg2] "{r1}" (arg2),
45
+ [arg3] "{r2}" (arg3),
46
+ [arg4] "{r3}" (arg4),
47
+ : .{ .memory = true });
48
+ }
49
+
50
+ pub fn syscall5(number: SYS, arg1: u32, arg2: u32, arg3: u32, arg4: u32, arg5: u32) u32 {
51
+ return asm volatile ("trap_s 0"
52
+ : [ret] "={r0}" (-> u32),
53
+ : [number] "{r8}" (@intFromEnum(number)),
54
+ [arg1] "{r0}" (arg1),
55
+ [arg2] "{r1}" (arg2),
56
+ [arg3] "{r2}" (arg3),
57
+ [arg4] "{r3}" (arg4),
58
+ [arg5] "{r4}" (arg5),
59
+ : .{ .memory = true });
60
+ }
61
+
62
+ pub fn syscall6(
63
+ number: SYS,
64
+ arg1: u32,
65
+ arg2: u32,
66
+ arg3: u32,
67
+ arg4: u32,
68
+ arg5: u32,
69
+ arg6: u32,
70
+ ) u32 {
71
+ return asm volatile ("trap_s 0"
72
+ : [ret] "={r0}" (-> u32),
73
+ : [number] "{r8}" (@intFromEnum(number)),
74
+ [arg1] "{r0}" (arg1),
75
+ [arg2] "{r1}" (arg2),
76
+ [arg3] "{r2}" (arg3),
77
+ [arg4] "{r3}" (arg4),
78
+ [arg5] "{r4}" (arg5),
79
+ [arg6] "{r5}" (arg6),
80
+ : .{ .memory = true });
81
+ }
82
+
83
+ pub fn clone() callconv(.naked) u32 {
84
+ // __clone(func, stack, flags, arg, ptid, tls, ctid)
85
+ // r0, r1, r2, r3, r4, r5, r6
86
+ //
87
+ // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
88
+ // r8 r0, r1, r2, r3, r4
89
+ asm volatile (
90
+ \\ // Align stack pointer
91
+ \\ and r1, r1, -16
92
+ \\ mov r10, r0
93
+ \\ mov r11, r3
94
+ \\ // Setup the arguments
95
+ \\ mov r0, r2
96
+ \\ mov r2, r4
97
+ \\ mov r3, r5
98
+ \\ mov r4, r6
99
+ \\ mov r8, 220 // SYS_clone
100
+ \\ trap_s 0
101
+ \\ cmp r0, 0
102
+ \\ beq 1f
103
+ \\ j [blink]
104
+ \\ // Child
105
+ \\ 1:
106
+ );
107
+ if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
108
+ \\ .cfi_undefined blink
109
+ );
110
+
111
+ asm volatile (
112
+ \\ mov fp, 0
113
+ \\ mov blink, 0
114
+ \\
115
+ \\ mov r0, r11
116
+ \\ jl [r10]
117
+ \\
118
+ \\ // Exit
119
+ \\ mov r8, 93 // SYS_exit
120
+ \\ trap_s 0
121
+ );
122
+ }
123
+
124
+ pub const restore = restore_rt;
125
+
126
+ pub fn restore_rt() callconv(.naked) noreturn {
127
+ switch (builtin.zig_backend) {
128
+ .stage2_c => asm volatile (
129
+ \\ mov r8, %[number]
130
+ \\ trap_s 0
131
+ :
132
+ : [number] "I" (@intFromEnum(SYS.rt_sigreturn)),
133
+ ),
134
+ else => asm volatile (
135
+ \\ trap_s 0
136
+ :
137
+ : [number] "{r8}" (@intFromEnum(SYS.rt_sigreturn)),
138
+ ),
139
+ }
140
+ }
141
+
142
+ pub const time_t = i64;
143
+
144
+ pub const VDSO = void;
package/std/os/linux.zig CHANGED
@@ -31,6 +31,7 @@ test {
31
31
 
32
32
  const arch_bits = switch (native_arch) {
33
33
  .aarch64, .aarch64_be => @import("linux/aarch64.zig"),
34
+ .arc, .arceb => @import("linux/arc.zig"),
34
35
  .arm, .armeb, .thumb, .thumbeb => @import("linux/arm.zig"),
35
36
  .hexagon => @import("linux/hexagon.zig"),
36
37
  .loongarch32 => @import("linux/loongarch32.zig"),
@@ -274,7 +275,13 @@ pub const MAP = switch (native_arch) {
274
275
  UNINITIALIZED: bool = false,
275
276
  _: u5 = 0,
276
277
  },
277
- .hexagon, .m68k, .or1k, .s390x => packed struct(u32) {
278
+ .arc,
279
+ .arceb,
280
+ .hexagon,
281
+ .m68k,
282
+ .or1k,
283
+ .s390x,
284
+ => packed struct(u32) {
278
285
  TYPE: MAP_TYPE,
279
286
  FIXED: bool = false,
280
287
  ANONYMOUS: bool = false,
@@ -451,7 +458,12 @@ pub const O = switch (native_arch) {
451
458
  TMPFILE: bool = false,
452
459
  _23: u9 = 0,
453
460
  },
454
- .hexagon, .or1k, .s390x => packed struct(u32) {
461
+ .arc,
462
+ .arceb,
463
+ .hexagon,
464
+ .or1k,
465
+ .s390x,
466
+ => packed struct(u32) {
455
467
  ACCMODE: ACCMODE = .RDONLY,
456
468
  _2: u4 = 0,
457
469
  CREAT: bool = false,
@@ -1584,6 +1596,11 @@ pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
1584
1596
  return syscall2(.clone, flags, child_stack_ptr);
1585
1597
  }
1586
1598
 
1599
+ /// This call cannot fail, and the return value is the caller's thread id
1600
+ pub fn set_tid_address(tidptr: ?*pid_t) pid_t {
1601
+ return @intCast(@as(u32, @truncate(syscall1(.set_tid_address, @intFromPtr(tidptr)))));
1602
+ }
1603
+
1587
1604
  pub fn close(fd: fd_t) usize {
1588
1605
  return syscall1(.close, @as(usize, @bitCast(@as(isize, fd))));
1589
1606
  }
@@ -3878,8 +3895,8 @@ pub const W = struct {
3878
3895
  pub fn TERMSIG(s: u32) SIG {
3879
3896
  return @enumFromInt(s & 0x7f);
3880
3897
  }
3881
- pub fn STOPSIG(s: u32) u32 {
3882
- return EXITSTATUS(s);
3898
+ pub fn STOPSIG(s: u32) SIG {
3899
+ return @enumFromInt(EXITSTATUS(s));
3883
3900
  }
3884
3901
  pub fn IFEXITED(s: u32) bool {
3885
3902
  return (s & 0x7f) == 0;
@@ -3952,7 +3952,7 @@ inline fn MAKELANGID(p: c_ushort, s: c_ushort) LANGID {
3952
3952
  /// and you get an unexpected error.
3953
3953
  pub fn unexpectedError(err: Win32Error) UnexpectedError {
3954
3954
  @branchHint(.cold);
3955
- if (std.posix.unexpected_error_tracing) {
3955
+ if (std.options.unexpected_error_tracing) {
3956
3956
  std.debug.print("error.Unexpected: GetLastError({d}): {t}\n", .{ err, err });
3957
3957
  std.debug.dumpCurrentStackTrace(.{ .first_address = @returnAddress() });
3958
3958
  }
@@ -3962,7 +3962,7 @@ pub fn unexpectedError(err: Win32Error) UnexpectedError {
3962
3962
  /// Call this when you made a windows NtDll call
3963
3963
  /// and you get an unexpected status.
3964
3964
  pub fn unexpectedStatus(status: NTSTATUS) UnexpectedError {
3965
- if (std.posix.unexpected_error_tracing) {
3965
+ if (std.options.unexpected_error_tracing) {
3966
3966
  std.debug.print("error.Unexpected NTSTATUS=0x{x} ({s})\n", .{
3967
3967
  @intFromEnum(status),
3968
3968
  std.enums.tagName(NTSTATUS, status) orelse "<unnamed>",
package/std/pdb.zig CHANGED
@@ -314,11 +314,9 @@ pub const SymbolKind = enum(u16) {
314
314
 
315
315
  pub const TypeIndex = u32;
316
316
 
317
- // TODO According to this header:
318
- // https://github.com/microsoft/microsoft-pdb/blob/082c5290e5aff028ae84e43affa8be717aa7af73/include/cvinfo.h#L3722
319
- // we should define RecordPrefix as part of the ProcSym structure.
320
- // This might be important when we start generating PDB in self-hosted with our own PE linker.
321
317
  pub const ProcSym = extern struct {
318
+ record_len: u16,
319
+ record_kind: SymbolKind,
322
320
  parent: u32,
323
321
  end: u32,
324
322
  next: u32,
@@ -508,3 +506,144 @@ pub const SuperBlock = extern struct {
508
506
  // implement it so we're kind of safe making this assumption for now.
509
507
  block_map_addr: u32,
510
508
  };
509
+
510
+ pub const IpiStreamVersion = enum(u32) {
511
+ v40 = 19950410,
512
+ v41 = 19951122,
513
+ v50 = 19961031,
514
+ v70 = 19990903,
515
+ v80 = 20040203,
516
+ _,
517
+ };
518
+
519
+ pub const IpiStreamHeader = extern struct {
520
+ version: IpiStreamVersion,
521
+ header_size: u32,
522
+ type_index_begin: u32,
523
+ type_index_end: u32,
524
+ type_record_bytes: u32,
525
+ hash_stream_index: u16,
526
+ hash_aux_stream_index: u16,
527
+ hash_key_size: u32,
528
+ num_hash_buckets: u32,
529
+ hash_value_buffer_offset: i32,
530
+ hash_value_buffer_length: u32,
531
+ index_offset_buffer_offset: i32,
532
+ index_offset_buffer_length: u32,
533
+ hash_adj_buffer_offset: i32,
534
+ hash_adj_buffer_length: u32,
535
+ };
536
+
537
+ pub const LfRecordPrefix = extern struct {
538
+ len: u16,
539
+ kind: LfRecordKind,
540
+ };
541
+
542
+ pub const LfRecordKind = enum(u16) {
543
+ pointer = 0x1002,
544
+ modifier = 0x1001,
545
+ procedure = 0x1008,
546
+ mfunction = 0x1009,
547
+ label = 0x000e,
548
+ arglist = 0x1201,
549
+ fieldlist = 0x1203,
550
+ array = 0x1503,
551
+ class = 0x1504,
552
+ structure = 0x1505,
553
+ interface = 0x1519,
554
+ @"union" = 0x1506,
555
+ @"enum" = 0x1507,
556
+ typeserver2 = 0x1515,
557
+ vftable = 0x151d,
558
+ vtshape = 0x000a,
559
+ bitfield = 0x1205,
560
+ func_id = 0x1601,
561
+ mfunc_id = 0x1602,
562
+ buildinfo = 0x1603,
563
+ substr_list = 0x1604,
564
+ string_id = 0x1605,
565
+ udt_src_line = 0x1606,
566
+ udt_mod_src_line = 0x1607,
567
+ methodlist = 0x1206,
568
+ precomp = 0x1509,
569
+ endprecomp = 0x0014,
570
+ bclass = 0x1400,
571
+ binterface = 0x151a,
572
+ vbclass = 0x1401,
573
+ ivbclass = 0x1402,
574
+ vfunctab = 0x1409,
575
+ stmember = 0x150e,
576
+ method = 0x150f,
577
+ member = 0x150d,
578
+ nesttype = 0x1510,
579
+ onemethod = 0x1511,
580
+ enumerate = 0x1502,
581
+ index = 0x1404,
582
+ pad0 = 0xf0,
583
+ _,
584
+ };
585
+
586
+ pub const LfFuncId = extern struct {
587
+ len: u16,
588
+ kind: LfRecordKind,
589
+ scope_id: u32,
590
+ type: u32,
591
+ name: [1]u8, // null-terminated
592
+ };
593
+
594
+ pub const LfMFuncId = extern struct {
595
+ len: u16,
596
+ kind: LfRecordKind,
597
+ parent_type: u32,
598
+ type: u32,
599
+ name: [1]u8, // null-terminated
600
+ };
601
+
602
+ pub const InlineSiteSym = extern struct {
603
+ record_len: u16,
604
+ record_kind: SymbolKind,
605
+ parent: u32,
606
+ end: u32,
607
+ inlinee: u32,
608
+ };
609
+
610
+ pub const InlineSiteSym2 = extern struct {
611
+ record_len: u16,
612
+ record_kind: SymbolKind,
613
+ parent: u32,
614
+ end: u32,
615
+ inlinee: u32,
616
+ invocations: u32,
617
+ };
618
+
619
+ pub const InlineeSourceLineSignature = enum(u32) { normal = 0, ex = 1, _ };
620
+
621
+ pub const InlineeSourceLine = extern struct {
622
+ inlinee: u32,
623
+ file_id: u32,
624
+ source_line_num: u32,
625
+ };
626
+
627
+ pub const InlineeSourceLineEx = extern struct {
628
+ inlinee: u32,
629
+ file_id: u32,
630
+ source_line_num: u32,
631
+ count_of_extra_files: u32,
632
+ };
633
+
634
+ pub const BinaryAnnotationOpcode = enum(u8) {
635
+ invalid = 0,
636
+ code_offset = 1,
637
+ change_code_offset_base = 2,
638
+ change_code_offset = 3,
639
+ change_code_length = 4,
640
+ change_file = 5,
641
+ change_line_offset = 6,
642
+ change_line_end_delta = 7,
643
+ change_range_kind = 8,
644
+ change_column_start = 9,
645
+ change_column_end_delta = 10,
646
+ change_code_offset_and_line_offset = 11,
647
+ change_code_length_and_code_offset = 12,
648
+ change_column_end = 13,
649
+ };
package/std/posix.zig CHANGED
@@ -513,6 +513,9 @@ pub const GetSockNameError = error{
513
513
  SocketNotBound,
514
514
 
515
515
  FileDescriptorNotASocket,
516
+
517
+ /// The socket is not connected (connection-oriented sockets only).
518
+ SocketUnconnected,
516
519
  } || UnexpectedError;
517
520
 
518
521
  pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSockNameError!void {
@@ -529,6 +532,7 @@ pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
529
532
  .INVAL => unreachable, // invalid parameters
530
533
  .NOTSOCK => return error.FileDescriptorNotASocket,
531
534
  .NOBUFS => return error.SystemResources,
535
+ .NOTCONN => return error.SocketUnconnected,
532
536
  }
533
537
  }
534
538
  }
@@ -682,7 +686,7 @@ pub fn munmap(memory: []align(page_size_min) const u8) void {
682
686
  .SUCCESS => return,
683
687
  .INVAL => unreachable, // Invalid parameters.
684
688
  .NOMEM => unreachable, // Attempted to unmap a region in the middle of an existing mapping.
685
- else => |e| if (unexpected_error_tracing) {
689
+ else => |e| if (std.options.unexpected_error_tracing) {
686
690
  std.debug.panic("unexpected errno: {d} ({t})", .{ @intFromEnum(e), e });
687
691
  } else unreachable,
688
692
  }
@@ -1658,22 +1662,12 @@ pub fn name_to_handle_atZ(
1658
1662
 
1659
1663
  pub const lfs64_abi = native_os == .linux and builtin.link_libc and (builtin.abi.isGnu() or builtin.abi.isAndroid());
1660
1664
 
1661
- /// Whether or not `error.Unexpected` will print its value and a stack trace.
1662
- ///
1663
- /// If this happens the fix is to add the error code to the corresponding
1664
- /// switch expression, possibly introduce a new error in the error set, and
1665
- /// send a patch to Zig.
1666
- pub const unexpected_error_tracing = builtin.mode == .Debug and switch (builtin.zig_backend) {
1667
- .stage2_llvm, .stage2_x86_64 => true,
1668
- else => false,
1669
- };
1670
-
1671
1665
  pub const UnexpectedError = std.Io.UnexpectedError;
1672
1666
 
1673
1667
  /// Call this when you made a syscall or something that sets errno
1674
1668
  /// and you get an unexpected error.
1675
1669
  pub fn unexpectedErrno(err: E) UnexpectedError {
1676
- if (unexpected_error_tracing) {
1670
+ if (std.options.unexpected_error_tracing) {
1677
1671
  std.debug.print("unexpected errno: {d}\n", .{@intFromEnum(err)});
1678
1672
  std.debug.dumpCurrentStackTrace(.{});
1679
1673
  }