@zigc/lib 0.16.0-dev.3091 → 0.16.0-dev.3121
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.
- package/c/math.zig +111 -22
- package/compiler_rt/cos.zig +141 -52
- package/compiler_rt/long_double.zig +37 -0
- package/compiler_rt/rem_pio2l.zig +173 -0
- package/compiler_rt/sin.zig +140 -55
- package/compiler_rt/sincos.zig +279 -72
- package/compiler_rt/tan.zig +118 -47
- package/compiler_rt/trig.zig +256 -6
- package/package.json +1 -1
- package/std/debug/Info.zig +4 -0
- package/std/heap/ArenaAllocator.zig +145 -154
- package/std/mem/Allocator.zig +4 -5
- package/std/mem.zig +48 -0
- package/libc/mingw/math/arm/sincos.S +0 -30
- package/libc/mingw/math/arm-common/sincosl.c +0 -13
- package/libc/mingw/math/arm64/rint.c +0 -12
- package/libc/mingw/math/arm64/rintf.c +0 -12
- package/libc/mingw/math/arm64/sincos.S +0 -32
- package/libc/mingw/math/frexpf.c +0 -13
- package/libc/mingw/math/frexpl.c +0 -71
- package/libc/mingw/math/x86/cos.def.h +0 -65
- package/libc/mingw/math/x86/cosl.c +0 -46
- package/libc/mingw/math/x86/cosl_internal.S +0 -55
- package/libc/mingw/math/x86/sin.def.h +0 -65
- package/libc/mingw/math/x86/sinl.c +0 -46
- package/libc/mingw/math/x86/sinl_internal.S +0 -58
- package/libc/mingw/math/x86/tanl.S +0 -62
- package/libc/musl/src/math/__cosl.c +0 -96
- package/libc/musl/src/math/__sinl.c +0 -78
- package/libc/musl/src/math/__tanl.c +0 -143
- package/libc/musl/src/math/aarch64/lrint.c +0 -10
- package/libc/musl/src/math/aarch64/lrintf.c +0 -10
- package/libc/musl/src/math/aarch64/rintf.c +0 -7
- package/libc/musl/src/math/cosl.c +0 -39
- package/libc/musl/src/math/finite.c +0 -7
- package/libc/musl/src/math/finitef.c +0 -7
- package/libc/musl/src/math/frexp.c +0 -23
- package/libc/musl/src/math/frexpf.c +0 -23
- package/libc/musl/src/math/frexpl.c +0 -29
- package/libc/musl/src/math/i386/lrint.c +0 -8
- package/libc/musl/src/math/i386/lrintf.c +0 -8
- package/libc/musl/src/math/i386/rintf.c +0 -7
- package/libc/musl/src/math/lrint.c +0 -72
- package/libc/musl/src/math/lrintf.c +0 -8
- package/libc/musl/src/math/powerpc64/lrint.c +0 -16
- package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
- package/libc/musl/src/math/rintf.c +0 -30
- package/libc/musl/src/math/s390x/rintf.c +0 -15
- package/libc/musl/src/math/sincosl.c +0 -60
- package/libc/musl/src/math/sinl.c +0 -41
- package/libc/musl/src/math/tanl.c +0 -29
- package/libc/musl/src/math/x32/lrint.s +0 -5
- package/libc/musl/src/math/x32/lrintf.s +0 -5
- package/libc/musl/src/math/x86_64/lrint.c +0 -8
- package/libc/musl/src/math/x86_64/lrintf.c +0 -8
|
@@ -358,14 +358,16 @@ fn alloc(ctx: *anyopaque, n: usize, alignment: Alignment, ret_addr: usize) ?[*]u
|
|
|
358
358
|
const end_index = @atomicRmw(usize, &node.end_index, .Add, alignable, .acquire); // acquire any memory that may have been freed
|
|
359
359
|
const aligned_index = alignedIndex(buf.ptr, end_index, alignment);
|
|
360
360
|
assert(end_index + alignable >= aligned_index + n);
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
361
|
+
if (end_index + alignable != aligned_index + n) {
|
|
362
|
+
_ = @cmpxchgStrong(
|
|
363
|
+
usize,
|
|
364
|
+
&node.end_index,
|
|
365
|
+
end_index + alignable,
|
|
366
|
+
aligned_index + n,
|
|
367
|
+
.monotonic, // no need to release alignment padding; there's no one accessing it!
|
|
368
|
+
.monotonic,
|
|
369
|
+
);
|
|
370
|
+
}
|
|
369
371
|
|
|
370
372
|
if (aligned_index + n > buf.len) break :first_node .{ node, buf.len };
|
|
371
373
|
return buf[aligned_index..][0..n].ptr;
|
|
@@ -682,45 +684,40 @@ test "reset while retaining a buffer" {
|
|
|
682
684
|
try std.testing.expectEqual(2, arena_allocator.queryCapacity());
|
|
683
685
|
}
|
|
684
686
|
|
|
685
|
-
test "fuzz" {
|
|
687
|
+
test "fuzz multi threaded" {
|
|
686
688
|
@disableInstrumentation();
|
|
687
689
|
if (@import("builtin").single_threaded) return error.SkipZigTest;
|
|
688
690
|
|
|
689
691
|
const gpa = std.heap.smp_allocator;
|
|
690
692
|
|
|
693
|
+
var io_instance: std.Io.Threaded = .init(gpa, .{});
|
|
694
|
+
defer io_instance.deinit();
|
|
695
|
+
|
|
691
696
|
var arena_state: ArenaAllocator.State = .init;
|
|
692
697
|
// No need to deinit arena_state, all allocations are in `sample_buffer`!
|
|
693
698
|
|
|
694
|
-
const
|
|
699
|
+
const buffer_size = FuzzContext.max_alloc_count * FuzzContext.max_alloc_size;
|
|
700
|
+
|
|
701
|
+
const control_buffer = try gpa.alloc(u8, buffer_size);
|
|
695
702
|
defer gpa.free(control_buffer);
|
|
696
703
|
var control_instance: std.heap.FixedBufferAllocator = .init(control_buffer);
|
|
697
704
|
|
|
698
|
-
const sample_buffer = try gpa.alloc(u8,
|
|
705
|
+
const sample_buffer = try gpa.alloc(u8, buffer_size);
|
|
699
706
|
defer gpa.free(sample_buffer);
|
|
700
707
|
var sample_instance: FuzzAllocator = .init(sample_buffer);
|
|
701
708
|
|
|
702
|
-
var allocs: FuzzContext.Allocs = try .initCapacity(gpa, FuzzContext.max_alloc_count);
|
|
703
|
-
defer allocs.deinit(gpa);
|
|
704
|
-
|
|
705
709
|
try std.testing.fuzz(FuzzContext.Init{
|
|
706
|
-
.
|
|
707
|
-
.allocs = &allocs,
|
|
710
|
+
.threaded_instance = &io_instance,
|
|
708
711
|
.arena_state = &arena_state,
|
|
709
712
|
.control_instance = &control_instance,
|
|
710
713
|
.sample_instance = &sample_instance,
|
|
711
|
-
},
|
|
714
|
+
}, fuzzMultiThreaded, .{});
|
|
712
715
|
}
|
|
713
716
|
|
|
714
|
-
fn
|
|
717
|
+
fn fuzzMultiThreaded(fuzz_init: FuzzContext.Init, smith: *std.testing.Smith) anyerror!void {
|
|
715
718
|
@disableInstrumentation();
|
|
716
719
|
const testing = std.testing;
|
|
717
|
-
|
|
718
|
-
// We use a 'fresh' `Threaded` instance every time to reset threadlocals to
|
|
719
|
-
// their default values.
|
|
720
|
-
|
|
721
|
-
var io_instance: std.Io.Threaded = .init(fuzz_init.gpa, .{});
|
|
722
|
-
defer io_instance.deinit();
|
|
723
|
-
const io = io_instance.io();
|
|
720
|
+
const io = fuzz_init.threaded_instance.io();
|
|
724
721
|
|
|
725
722
|
fuzz_init.sample_instance.prepareFailures(smith);
|
|
726
723
|
|
|
@@ -731,59 +728,57 @@ fn fuzzArenaAllocator(fuzz_init: FuzzContext.Init, smith: *std.testing.Smith) an
|
|
|
731
728
|
defer fuzz_init.arena_state.* = arena_instance.state;
|
|
732
729
|
|
|
733
730
|
var ctx: FuzzContext = .init(
|
|
734
|
-
io,
|
|
735
731
|
control_allocator,
|
|
736
732
|
arena_instance.allocator(),
|
|
737
|
-
fuzz_init.allocs,
|
|
738
733
|
);
|
|
739
734
|
defer ctx.deinit();
|
|
740
735
|
|
|
741
|
-
ctx.rwl.lockUncancelable(io);
|
|
742
|
-
|
|
743
736
|
var group: std.Io.Group = .init;
|
|
744
737
|
defer group.cancel(io);
|
|
745
738
|
|
|
739
|
+
var n_allocs: usize = 0;
|
|
746
740
|
var n_actions: usize = 0;
|
|
747
741
|
while (!smith.eosWeightedSimple(99, 1) and n_actions < FuzzContext.max_action_count) {
|
|
748
742
|
errdefer comptime unreachable;
|
|
749
743
|
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
.
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
744
|
+
const weights: []const testing.Smith.Weight = if (n_allocs == FuzzContext.max_alloc_count)
|
|
745
|
+
&.{
|
|
746
|
+
.value(FuzzContext.Action, .resize, 1),
|
|
747
|
+
.value(FuzzContext.Action, .remap, 1),
|
|
748
|
+
.value(FuzzContext.Action, .free, 1),
|
|
749
|
+
}
|
|
750
|
+
else
|
|
751
|
+
&.{
|
|
752
|
+
.value(FuzzContext.Action, .resize, 1),
|
|
753
|
+
.value(FuzzContext.Action, .remap, 1),
|
|
754
|
+
.value(FuzzContext.Action, .free, 1),
|
|
755
|
+
.value(FuzzContext.Action, .alloc, 3),
|
|
756
|
+
};
|
|
757
|
+
switch (smith.valueWeighted(FuzzContext.Action, weights)) {
|
|
758
|
+
.alloc => {
|
|
759
|
+
const alloc_index = n_allocs;
|
|
760
|
+
n_allocs += 1;
|
|
761
|
+
ctx.allocs[alloc_index].common.len = .free;
|
|
762
|
+
group.concurrent(io, FuzzContext.doOneAlloc, .{
|
|
763
|
+
&ctx,
|
|
764
|
+
nextLen(smith),
|
|
765
|
+
smith.valueRangeAtMost(
|
|
768
766
|
Alignment,
|
|
769
767
|
.@"1",
|
|
770
768
|
.fromByteUnits(2 * std.heap.page_size_max),
|
|
771
769
|
),
|
|
772
|
-
|
|
773
|
-
}
|
|
770
|
+
@enumFromInt(alloc_index),
|
|
771
|
+
}) catch unreachable;
|
|
774
772
|
},
|
|
775
|
-
.resize => .
|
|
776
|
-
.remap => .
|
|
777
|
-
.free => .
|
|
778
|
-
}
|
|
779
|
-
group.concurrent(io, FuzzContext.doOneAction, .{ &ctx, action }) catch break;
|
|
773
|
+
.resize => group.concurrent(io, FuzzContext.doOneResize, .{ &ctx, nextLen(smith) }) catch unreachable,
|
|
774
|
+
.remap => group.concurrent(io, FuzzContext.doOneRemap, .{ &ctx, nextLen(smith) }) catch unreachable,
|
|
775
|
+
.free => group.concurrent(io, FuzzContext.doOneFree, .{&ctx}) catch unreachable,
|
|
776
|
+
}
|
|
780
777
|
n_actions += 1;
|
|
781
778
|
}
|
|
782
779
|
|
|
783
|
-
ctx.rwl.unlock(io);
|
|
784
|
-
|
|
785
780
|
try group.await(io);
|
|
786
|
-
try ctx.check();
|
|
781
|
+
try ctx.check(n_allocs);
|
|
787
782
|
|
|
788
783
|
// This also covers the `deinit` logic since `free_all` uses it internally.
|
|
789
784
|
|
|
@@ -806,73 +801,71 @@ fn fuzzArenaAllocator(fuzz_init: FuzzContext.Init, smith: *std.testing.Smith) an
|
|
|
806
801
|
}
|
|
807
802
|
|
|
808
803
|
fuzz_init.control_instance.reset();
|
|
809
|
-
fuzz_init.allocs.clearRetainingCapacity();
|
|
810
|
-
}
|
|
811
|
-
fn nextLen(smith: *std.testing.Smith) usize {
|
|
812
|
-
@disableInstrumentation();
|
|
813
|
-
return usizeRange(smith, 1, 16 << 10 << 10);
|
|
814
804
|
}
|
|
815
|
-
fn
|
|
805
|
+
fn nextLen(smith: *std.testing.Smith) @typeInfo(FuzzContext.Alloc.Len).@"enum".tag_type {
|
|
816
806
|
@disableInstrumentation();
|
|
817
|
-
const
|
|
818
|
-
return smith.valueRangeAtMost(
|
|
807
|
+
const BackingInt = @typeInfo(FuzzContext.Alloc.Len).@"enum".tag_type;
|
|
808
|
+
return smith.valueRangeAtMost(BackingInt, 1, FuzzContext.max_alloc_size);
|
|
819
809
|
}
|
|
820
810
|
|
|
821
811
|
const FuzzContext = struct {
|
|
822
|
-
io: std.Io,
|
|
823
|
-
rwl: std.Io.RwLock,
|
|
824
|
-
|
|
825
812
|
control_allocator: Allocator,
|
|
826
813
|
sample_allocator: Allocator,
|
|
827
814
|
|
|
828
|
-
|
|
815
|
+
last_alloc_index: Alloc.Index,
|
|
816
|
+
allocs: [max_alloc_count]Alloc,
|
|
829
817
|
|
|
830
|
-
const max_alloc_count =
|
|
818
|
+
const max_alloc_count = 64;
|
|
831
819
|
const max_action_count = 2 * max_alloc_count;
|
|
832
820
|
|
|
833
|
-
const
|
|
821
|
+
const max_alloc_size = 16 << 10;
|
|
822
|
+
|
|
823
|
+
const Alloc = struct {
|
|
834
824
|
control_ptr: [*]u8,
|
|
835
825
|
sample_ptr: [*]u8,
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
826
|
+
common: packed struct(usize) {
|
|
827
|
+
len: Len,
|
|
828
|
+
alignment: Alignment,
|
|
829
|
+
_: @Int(.unsigned, padding_bits) = 0,
|
|
830
|
+
},
|
|
831
|
+
|
|
832
|
+
const Len = enum(@Int(.unsigned, len_bits)) {
|
|
833
|
+
free = (1 << len_bits) - 1,
|
|
834
|
+
_,
|
|
835
|
+
};
|
|
836
|
+
const len_bits = @min(64, @bitSizeOf(usize)) - @bitSizeOf(Alignment);
|
|
837
|
+
const padding_bits = @bitSizeOf(usize) - (len_bits + @bitSizeOf(Alignment));
|
|
839
838
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
839
|
+
const Index = enum(usize) {
|
|
840
|
+
none = std.math.maxInt(usize),
|
|
841
|
+
_,
|
|
842
|
+
};
|
|
843
843
|
};
|
|
844
844
|
|
|
845
|
-
const Action =
|
|
846
|
-
alloc
|
|
847
|
-
resize
|
|
848
|
-
remap
|
|
845
|
+
const Action = enum {
|
|
846
|
+
alloc,
|
|
847
|
+
resize,
|
|
848
|
+
remap,
|
|
849
849
|
free,
|
|
850
850
|
};
|
|
851
851
|
|
|
852
|
-
threadlocal var tls_next: u8 = 0;
|
|
853
|
-
threadlocal var tls_last_index: ?usize = null;
|
|
854
|
-
|
|
855
852
|
const Init = struct {
|
|
856
|
-
|
|
857
|
-
allocs: *FuzzContext.Allocs,
|
|
853
|
+
threaded_instance: *std.Io.Threaded,
|
|
858
854
|
arena_state: *ArenaAllocator.State,
|
|
859
855
|
control_instance: *std.heap.FixedBufferAllocator,
|
|
860
856
|
sample_instance: *FuzzAllocator,
|
|
861
857
|
};
|
|
862
858
|
|
|
863
859
|
fn init(
|
|
864
|
-
io: std.Io,
|
|
865
860
|
control_allocator: Allocator,
|
|
866
861
|
sample_allocator: Allocator,
|
|
867
|
-
allocs: *Allocs,
|
|
868
862
|
) FuzzContext {
|
|
869
863
|
@disableInstrumentation();
|
|
870
864
|
return .{
|
|
871
|
-
.io = io,
|
|
872
|
-
.rwl = .init,
|
|
873
865
|
.control_allocator = control_allocator,
|
|
874
866
|
.sample_allocator = sample_allocator,
|
|
875
|
-
.
|
|
867
|
+
.last_alloc_index = .none,
|
|
868
|
+
.allocs = undefined,
|
|
876
869
|
};
|
|
877
870
|
}
|
|
878
871
|
|
|
@@ -881,35 +874,22 @@ const FuzzContext = struct {
|
|
|
881
874
|
ctx.* = undefined;
|
|
882
875
|
}
|
|
883
876
|
|
|
884
|
-
fn check(ctx: *const FuzzContext) !void {
|
|
877
|
+
fn check(ctx: *const FuzzContext, n_allocs: usize) !void {
|
|
885
878
|
@disableInstrumentation();
|
|
886
|
-
for (
|
|
887
|
-
const len: usize = switch (
|
|
879
|
+
for (ctx.allocs[0..n_allocs]) |allocation| {
|
|
880
|
+
const len: usize = switch (allocation.common.len) {
|
|
888
881
|
.free => continue,
|
|
889
882
|
_ => |len| @intFromEnum(len),
|
|
890
883
|
};
|
|
891
|
-
const control =
|
|
892
|
-
const sample =
|
|
884
|
+
const control = allocation.control_ptr[0..len];
|
|
885
|
+
const sample = allocation.sample_ptr[0..len];
|
|
893
886
|
try std.testing.expectEqualSlices(u8, control, sample);
|
|
894
887
|
}
|
|
895
888
|
}
|
|
896
889
|
|
|
897
|
-
fn
|
|
890
|
+
fn doOneAlloc(ctx: *FuzzContext, len: usize, alignment: Alignment, index: Alloc.Index) void {
|
|
898
891
|
@disableInstrumentation();
|
|
899
|
-
ctx.
|
|
900
|
-
defer ctx.rwl.unlockShared(ctx.io);
|
|
901
|
-
|
|
902
|
-
switch (action) {
|
|
903
|
-
.alloc => |act| ctx.doOneAlloc(act.len, act.alignment, act.index),
|
|
904
|
-
.resize => |act| ctx.doOneResize(act.new_len),
|
|
905
|
-
.remap => |act| ctx.doOneRemap(act.new_len),
|
|
906
|
-
.free => ctx.doOneFree(),
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
fn doOneAlloc(ctx: *FuzzContext, len: usize, alignment: Alignment, index: usize) void {
|
|
911
|
-
@disableInstrumentation();
|
|
912
|
-
assert(ctx.allocs.items(.len)[index] == .free);
|
|
892
|
+
assert(ctx.allocs[@intFromEnum(index)].common.len == .free);
|
|
913
893
|
|
|
914
894
|
const control_ptr = ctx.control_allocator.rawAlloc(len, alignment, @returnAddress()) orelse
|
|
915
895
|
return;
|
|
@@ -918,38 +898,42 @@ const FuzzContext = struct {
|
|
|
918
898
|
return;
|
|
919
899
|
};
|
|
920
900
|
|
|
921
|
-
ctx.allocs
|
|
901
|
+
ctx.allocs[@intFromEnum(index)] = .{
|
|
922
902
|
.control_ptr = control_ptr,
|
|
923
903
|
.sample_ptr = sample_ptr,
|
|
924
|
-
.
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
904
|
+
.common = .{
|
|
905
|
+
.len = @enumFromInt(len),
|
|
906
|
+
.alignment = alignment,
|
|
907
|
+
},
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
for (control_ptr[0..len], sample_ptr[0..len], 0..) |*control, *sample, i| {
|
|
911
|
+
control.* = @truncate(i);
|
|
912
|
+
sample.* = @truncate(i);
|
|
932
913
|
}
|
|
933
914
|
|
|
934
|
-
|
|
915
|
+
@atomicStore(Alloc.Index, &ctx.last_alloc_index, index, .release);
|
|
935
916
|
}
|
|
936
917
|
fn doOneResize(ctx: *FuzzContext, new_len: usize) void {
|
|
937
918
|
@disableInstrumentation();
|
|
938
|
-
const index = tls_last_index orelse return;
|
|
939
|
-
const len = ctx.allocs.items(.len)[index];
|
|
940
|
-
assert(len != .free);
|
|
941
|
-
const memory = ctx.allocs.items(.sample_ptr)[index][0..@intFromEnum(len)];
|
|
942
|
-
const alignment = ctx.allocs.items(.alignment)[index];
|
|
943
919
|
|
|
944
|
-
|
|
945
|
-
|
|
920
|
+
const index = @atomicRmw(Alloc.Index, &ctx.last_alloc_index, .Xchg, .none, .acquire);
|
|
921
|
+
if (index == .none) return;
|
|
922
|
+
|
|
923
|
+
const allocation = &ctx.allocs[@intFromEnum(index)];
|
|
924
|
+
assert(allocation.common.len != .free);
|
|
925
|
+
const memory = allocation.sample_ptr[0..@intFromEnum(allocation.common.len)];
|
|
926
|
+
const alignment = allocation.common.alignment;
|
|
927
|
+
|
|
928
|
+
assert(alignment.check(@intFromPtr(allocation.control_ptr)));
|
|
929
|
+
assert(alignment.check(@intFromPtr(allocation.sample_ptr)));
|
|
946
930
|
|
|
947
931
|
// Since `resize` is fallible, we have to ensure that `control_allocator`
|
|
948
932
|
// is always successful by reserving the memory we need beforehand.
|
|
949
933
|
const new_control_ptr = ctx.control_allocator.rawAlloc(new_len, alignment, @returnAddress()) orelse
|
|
950
934
|
return;
|
|
951
935
|
if (ctx.sample_allocator.rawResize(memory, alignment, new_len, @returnAddress())) {
|
|
952
|
-
const old_control =
|
|
936
|
+
const old_control = allocation.control_ptr[0..memory.len];
|
|
953
937
|
const overlap = @min(memory.len, new_len);
|
|
954
938
|
@memcpy(new_control_ptr[0..overlap], old_control[0..overlap]);
|
|
955
939
|
ctx.control_allocator.rawFree(old_control, alignment, @returnAddress());
|
|
@@ -958,23 +942,27 @@ const FuzzContext = struct {
|
|
|
958
942
|
return;
|
|
959
943
|
}
|
|
960
944
|
|
|
961
|
-
ctx.allocs
|
|
945
|
+
ctx.allocs[@intFromEnum(index)] = .{
|
|
962
946
|
.control_ptr = new_control_ptr,
|
|
963
947
|
.sample_ptr = memory.ptr,
|
|
964
|
-
.
|
|
965
|
-
|
|
966
|
-
|
|
948
|
+
.common = .{
|
|
949
|
+
.len = @enumFromInt(new_len),
|
|
950
|
+
.alignment = alignment,
|
|
951
|
+
},
|
|
952
|
+
};
|
|
967
953
|
|
|
968
954
|
if (new_len > memory.len) {
|
|
969
955
|
for (
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
956
|
+
allocation.control_ptr[memory.len..new_len],
|
|
957
|
+
allocation.sample_ptr[memory.len..new_len],
|
|
958
|
+
0..,
|
|
959
|
+
) |*control, *sample, i| {
|
|
960
|
+
control.* = @truncate(i);
|
|
961
|
+
sample.* = @truncate(i);
|
|
976
962
|
}
|
|
977
963
|
}
|
|
964
|
+
|
|
965
|
+
@atomicStore(Alloc.Index, &ctx.last_alloc_index, index, .release);
|
|
978
966
|
}
|
|
979
967
|
fn doOneRemap(ctx: *FuzzContext, new_len: usize) void {
|
|
980
968
|
@disableInstrumentation();
|
|
@@ -982,26 +970,29 @@ const FuzzContext = struct {
|
|
|
982
970
|
}
|
|
983
971
|
fn doOneFree(ctx: *FuzzContext) void {
|
|
984
972
|
@disableInstrumentation();
|
|
985
|
-
const index = tls_last_index orelse return;
|
|
986
|
-
const len = ctx.allocs.items(.len)[index];
|
|
987
|
-
assert(len != .free);
|
|
988
|
-
const memory = ctx.allocs.items(.sample_ptr)[index][0..@intFromEnum(len)];
|
|
989
|
-
const alignment = ctx.allocs.items(.alignment)[index];
|
|
990
973
|
|
|
991
|
-
|
|
992
|
-
|
|
974
|
+
const index = @atomicRmw(Alloc.Index, &ctx.last_alloc_index, .Xchg, .none, .acquire);
|
|
975
|
+
if (index == .none) return;
|
|
993
976
|
|
|
994
|
-
ctx.
|
|
995
|
-
|
|
977
|
+
const allocation = &ctx.allocs[@intFromEnum(index)];
|
|
978
|
+
assert(allocation.common.len != .free);
|
|
979
|
+
const len: usize = @intFromEnum(allocation.common.len);
|
|
980
|
+
const alignment = allocation.common.alignment;
|
|
996
981
|
|
|
997
|
-
|
|
982
|
+
assert(alignment.check(@intFromPtr(allocation.control_ptr)));
|
|
983
|
+
assert(alignment.check(@intFromPtr(allocation.sample_ptr)));
|
|
984
|
+
|
|
985
|
+
ctx.control_allocator.rawFree(allocation.control_ptr[0..len], alignment, @returnAddress());
|
|
986
|
+
ctx.sample_allocator.rawFree(allocation.sample_ptr[0..len], alignment, @returnAddress());
|
|
987
|
+
|
|
988
|
+
ctx.allocs[@intFromEnum(index)] = .{
|
|
998
989
|
.control_ptr = undefined,
|
|
999
990
|
.sample_ptr = undefined,
|
|
1000
|
-
.
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
991
|
+
.common = .{
|
|
992
|
+
.len = .free,
|
|
993
|
+
.alignment = .@"1",
|
|
994
|
+
},
|
|
995
|
+
};
|
|
1005
996
|
}
|
|
1006
997
|
};
|
|
1007
998
|
|
package/std/mem/Allocator.zig
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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
|
|
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 {
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has no copyright assigned and is placed in the Public Domain.
|
|
3
|
-
* This file is part of the mingw-w64 runtime package.
|
|
4
|
-
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
|
5
|
-
*/
|
|
6
|
-
#include <_mingw_mac.h>
|
|
7
|
-
|
|
8
|
-
.file "sincos.S"
|
|
9
|
-
.text
|
|
10
|
-
.align 2
|
|
11
|
-
/* zig patch: remove sincos symbol because sincos in compiler_rt is used instead */
|
|
12
|
-
.globl __MINGW_USYMBOL(sincosl)
|
|
13
|
-
.def __MINGW_USYMBOL(sincosl); .scl 2; .type 32; .endef
|
|
14
|
-
__MINGW_USYMBOL(sincosl):
|
|
15
|
-
push {r4, r5, r11, lr}
|
|
16
|
-
add r11, sp, #8
|
|
17
|
-
vpush {d8}
|
|
18
|
-
|
|
19
|
-
mov r4, r0
|
|
20
|
-
mov r5, r1
|
|
21
|
-
vmov.f64 d8, d0
|
|
22
|
-
bl sin
|
|
23
|
-
vstr d0, [r4]
|
|
24
|
-
|
|
25
|
-
vmov.f64 d0, d8
|
|
26
|
-
bl cos
|
|
27
|
-
vstr d0, [r5]
|
|
28
|
-
|
|
29
|
-
vpop {d8}
|
|
30
|
-
pop {r4, r5, r11, pc}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has no copyright assigned and is placed in the Public Domain.
|
|
3
|
-
* This file is part of the mingw-w64 runtime package.
|
|
4
|
-
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
#include <math.h>
|
|
8
|
-
|
|
9
|
-
void sincosl(long double x, long double *s, long double *c)
|
|
10
|
-
{
|
|
11
|
-
*s = sinl(x);
|
|
12
|
-
*c = cosl(x);
|
|
13
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has no copyright assigned and is placed in the Public Domain.
|
|
3
|
-
* This file is part of the mingw-w64 runtime package.
|
|
4
|
-
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
|
5
|
-
*/
|
|
6
|
-
#include <math.h>
|
|
7
|
-
|
|
8
|
-
double rint (double x) {
|
|
9
|
-
double retval = 0.0;
|
|
10
|
-
__asm__ __volatile__ ("frintx %d0, %d1\n\t" : "=w" (retval) : "w" (x));
|
|
11
|
-
return retval;
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has no copyright assigned and is placed in the Public Domain.
|
|
3
|
-
* This file is part of the mingw-w64 runtime package.
|
|
4
|
-
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
|
5
|
-
*/
|
|
6
|
-
#include <math.h>
|
|
7
|
-
|
|
8
|
-
float rintf (float x) {
|
|
9
|
-
float retval = 0.0F;
|
|
10
|
-
__asm__ __volatile__ ("frintx %s0, %s1\n\t" : "=w" (retval) : "w" (x));
|
|
11
|
-
return retval;
|
|
12
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has no copyright assigned and is placed in the Public Domain.
|
|
3
|
-
* This file is part of the mingw-w64 runtime package.
|
|
4
|
-
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
|
5
|
-
*/
|
|
6
|
-
#include <_mingw_mac.h>
|
|
7
|
-
|
|
8
|
-
.file "sincos.S"
|
|
9
|
-
.text
|
|
10
|
-
.align 2
|
|
11
|
-
/* zig patch: remove sincos symbol because sincos in compiler_rt is used instead */
|
|
12
|
-
.globl __MINGW_USYMBOL(sincosl)
|
|
13
|
-
.def __MINGW_USYMBOL(sincosl); .scl 2; .type 32; .endef
|
|
14
|
-
__MINGW_USYMBOL(sincosl):
|
|
15
|
-
str d8, [sp, #-32]!
|
|
16
|
-
str x30, [sp, #8]
|
|
17
|
-
stp x19, x20, [sp, #16]
|
|
18
|
-
|
|
19
|
-
mov x19, x0
|
|
20
|
-
mov x20, x1
|
|
21
|
-
fmov d8, d0
|
|
22
|
-
bl sin
|
|
23
|
-
str d0, [x19]
|
|
24
|
-
|
|
25
|
-
fmov d0, d8
|
|
26
|
-
bl cos
|
|
27
|
-
str d0, [x20]
|
|
28
|
-
|
|
29
|
-
ldp x19, x20, [sp, #16]
|
|
30
|
-
ldr x30, [sp, #8]
|
|
31
|
-
ldr d8, [sp], #32
|
|
32
|
-
ret
|