| author | |
| committer | |
| log | 6a34da963b4712da7fa20079e6ab557455ffe4bf |
| tree | deda8f8f46e2033b1f6c3d19d8e2b52ae1fab9e6 |
| parent | 6f0aa801c80a434b7cc931e879d234a8de501e38 |
| parent | 09cbcf8841a0b80cdbdf40c2b48acccbaa945ce8 |
| signature |
5 files changed, 18 insertions(+), 14 deletions(-)
std/crypto/chacha20.zig+3-2| ... | @@ -142,7 +142,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32] | ... | @@ -142,7 +142,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32] |
| 142 | assert(in.len >= out.len); | 142 | assert(in.len >= out.len); |
| 143 | assert(counter +% (in.len >> 6) >= counter); | 143 | assert(counter +% (in.len >> 6) >= counter); |
| 144 | 144 | ||
| 145 | var cursor: u64 = 0; | 145 | var cursor: usize = 0; |
| 146 | var k: [8]u32 = undefined; | 146 | var k: [8]u32 = undefined; |
| 147 | var c: [4]u32 = undefined; | 147 | var c: [4]u32 = undefined; |
| 148 | 148 | ||
| ... | @@ -161,7 +161,8 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32] | ... | @@ -161,7 +161,8 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32] |
| 161 | c[3] = mem.readIntSliceLittle(u32, nonce[4..8]); | 161 | c[3] = mem.readIntSliceLittle(u32, nonce[4..8]); |
| 162 | 162 | ||
| 163 | const block_size = (1 << 6); | 163 | const block_size = (1 << 6); |
| 164 | const big_block = (block_size << 32); | 164 | // The full block size is greater than the address space on a 32bit machine |
| 165 | const big_block = if (@sizeOf(usize) > 4) (block_size << 32) else maxInt(usize); | ||
| 165 | 166 | ||
| 166 | // first partial big block | 167 | // first partial big block |
| 167 | if (((@intCast(u64, maxInt(u32) - @truncate(u32, counter)) + 1) << 6) < in.len) { | 168 | if (((@intCast(u64, maxInt(u32) - @truncate(u32, counter)) + 1) << 6) < in.len) { |
std/heap.zig+1-1| ... | @@ -603,7 +603,7 @@ test "ArenaAllocator" { | ... | @@ -603,7 +603,7 @@ test "ArenaAllocator" { |
| 603 | try testAllocatorAlignedShrink(&arena_allocator.allocator); | 603 | try testAllocatorAlignedShrink(&arena_allocator.allocator); |
| 604 | } | 604 | } |
| 605 | 605 | ||
| 606 | var test_fixed_buffer_allocator_memory: [40000 * @sizeOf(usize)]u8 = undefined; | 606 | var test_fixed_buffer_allocator_memory: [40000 * @sizeOf(u64)]u8 = undefined; |
| 607 | test "FixedBufferAllocator" { | 607 | test "FixedBufferAllocator" { |
| 608 | var fixed_buffer_allocator = FixedBufferAllocator.init(test_fixed_buffer_allocator_memory[0..]); | 608 | var fixed_buffer_allocator = FixedBufferAllocator.init(test_fixed_buffer_allocator_memory[0..]); |
| 609 | 609 |
std/os/linux.zig+2-2| ... | @@ -1101,8 +1101,8 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti | ... | @@ -1101,8 +1101,8 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti |
| 1101 | 1101 | ||
| 1102 | const NSIG = 65; | 1102 | const NSIG = 65; |
| 1103 | const sigset_t = [128 / @sizeOf(usize)]usize; | 1103 | const sigset_t = [128 / @sizeOf(usize)]usize; |
| 1104 | const all_mask = []usize{maxInt(usize)}; | 1104 | const all_mask = []u32{0xffffffff, 0xffffffff}; |
| 1105 | const app_mask = []usize{0xfffffffc7fffffff}; | 1105 | const app_mask = []u32{0xfffffffc, 0x7fffffff}; |
| 1106 | 1106 | ||
| 1107 | const k_sigaction = extern struct { | 1107 | const k_sigaction = extern struct { |
| 1108 | handler: extern fn (i32) void, | 1108 | handler: extern fn (i32) void, |
std/os/time.zig+10-7| ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); | ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); |
| 3 | const Os = builtin.Os; | 3 | const Os = builtin.Os; |
| 4 | const debug = std.debug; | 4 | const debug = std.debug; |
| 5 | const testing = std.testing; | 5 | const testing = std.testing; |
| 6 | const math = std.math; | ||
| 6 | 7 | ||
| 7 | const windows = std.os.windows; | 8 | const windows = std.os.windows; |
| 8 | const linux = std.os.linux; | 9 | const linux = std.os.linux; |
| ... | @@ -12,33 +13,34 @@ const posix = std.os.posix; | ... | @@ -12,33 +13,34 @@ const posix = std.os.posix; |
| 12 | 13 | ||
| 13 | pub const epoch = @import("epoch.zig"); | 14 | pub const epoch = @import("epoch.zig"); |
| 14 | 15 | ||
| 15 | /// Sleep for the specified duration | 16 | /// Spurious wakeups are possible and no precision of timing is guaranteed. |
| 16 | pub fn sleep(nanoseconds: u64) void { | 17 | pub fn sleep(nanoseconds: u64) void { |
| 17 | switch (builtin.os) { | 18 | switch (builtin.os) { |
| 18 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { | 19 | Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => { |
| 19 | const s = nanoseconds / ns_per_s; | 20 | const s = nanoseconds / ns_per_s; |
| 20 | const ns = nanoseconds % ns_per_s; | 21 | const ns = nanoseconds % ns_per_s; |
| 21 | posixSleep(@intCast(u63, s), @intCast(u63, ns)); | 22 | posixSleep(s, ns); |
| 22 | }, | 23 | }, |
| 23 | Os.windows => { | 24 | Os.windows => { |
| 24 | const ns_per_ms = ns_per_s / ms_per_s; | 25 | const ns_per_ms = ns_per_s / ms_per_s; |
| 25 | const milliseconds = nanoseconds / ns_per_ms; | 26 | const milliseconds = nanoseconds / ns_per_ms; |
| 26 | windows.Sleep(@intCast(windows.DWORD, milliseconds)); | 27 | const ms_that_will_fit = std.math.cast(windows.DWORD, milliseconds) catch std.math.maxInt(windows.DWORD); |
| 28 | windows.Sleep(ms_that_will_fit); | ||
| 27 | }, | 29 | }, |
| 28 | else => @compileError("Unsupported OS"), | 30 | else => @compileError("Unsupported OS"), |
| 29 | } | 31 | } |
| 30 | } | 32 | } |
| 31 | 33 | ||
| 32 | pub fn posixSleep(seconds: u63, nanoseconds: u63) void { | 34 | /// Spurious wakeups are possible and no precision of timing is guaranteed. |
| 35 | pub fn posixSleep(seconds: u64, nanoseconds: u64) void { | ||
| 33 | var req = posix.timespec{ | 36 | var req = posix.timespec{ |
| 34 | .tv_sec = seconds, | 37 | .tv_sec = std.math.cast(isize, seconds) catch std.math.maxInt(isize), |
| 35 | .tv_nsec = nanoseconds, | 38 | .tv_nsec = std.math.cast(isize, nanoseconds) catch std.math.maxInt(isize), |
| 36 | }; | 39 | }; |
| 37 | var rem: posix.timespec = undefined; | 40 | var rem: posix.timespec = undefined; |
| 38 | while (true) { | 41 | while (true) { |
| 39 | const ret_val = posix.nanosleep(&req, &rem); | 42 | const ret_val = posix.nanosleep(&req, &rem); |
| 40 | const err = posix.getErrno(ret_val); | 43 | const err = posix.getErrno(ret_val); |
| 41 | if (err == 0) return; | ||
| 42 | switch (err) { | 44 | switch (err) { |
| 43 | posix.EFAULT => unreachable, | 45 | posix.EFAULT => unreachable, |
| 44 | posix.EINVAL => { | 46 | posix.EINVAL => { |
| ... | @@ -50,6 +52,7 @@ pub fn posixSleep(seconds: u63, nanoseconds: u63) void { | ... | @@ -50,6 +52,7 @@ pub fn posixSleep(seconds: u63, nanoseconds: u63) void { |
| 50 | req = rem; | 52 | req = rem; |
| 51 | continue; | 53 | continue; |
| 52 | }, | 54 | }, |
| 55 | // This prong handles success as well as unexpected errors. | ||
| 53 | else => return, | 56 | else => return, |
| 54 | } | 57 | } |
| 55 | } | 58 | } |
std/rand.zig+2-2| ... | @@ -768,10 +768,10 @@ pub const Isaac64 = struct { | ... | @@ -768,10 +768,10 @@ pub const Isaac64 = struct { |
| 768 | const x = self.m[base + m1]; | 768 | const x = self.m[base + m1]; |
| 769 | self.a = mix +% self.m[base + m2]; | 769 | self.a = mix +% self.m[base + m2]; |
| 770 | 770 | ||
| 771 | const y = self.a +% self.b +% self.m[(x >> 3) % self.m.len]; | 771 | const y = self.a +% self.b +% self.m[@intCast(usize, (x >> 3) % self.m.len)]; |
| 772 | self.m[base + m1] = y; | 772 | self.m[base + m1] = y; |
| 773 | 773 | ||
| 774 | self.b = x +% self.m[(y >> 11) % self.m.len]; | 774 | self.b = x +% self.m[@intCast(usize, (y >> 11) % self.m.len)]; |
| 775 | self.r[self.r.len - 1 - base - m1] = self.b; | 775 | self.r[self.r.len - 1 - base - m1] = self.b; |
| 776 | } | 776 | } |
| 777 | 777 |