| author | |
| committer | |
| log | eaa6218f09d12fc84a29462f8287c0e6ecfd6739 |
| tree | b7d649de3f0f5185dbf2c5b75905edd33f271cf3 |
| parent | f5dbcd1cb4374be619ba0b18e40a069a7e860d93 |
This fixes issues targetting both `x86_64-linux` and `x86_64-macos` with
the self-hosted backend.5 files changed, 55 insertions(+), 24 deletions(-)
lib/std/crypto/Certificate/Bundle/macos.zig+2-2| ... | @@ -21,7 +21,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { | ... | @@ -21,7 +21,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { |
| 21 | const reader = stream.reader(); | 21 | const reader = stream.reader(); |
| 22 | 22 | ||
| 23 | const db_header = try reader.readStructEndian(ApplDbHeader, .big); | 23 | const db_header = try reader.readStructEndian(ApplDbHeader, .big); |
| 24 | assert(mem.eql(u8, "kych", &@as([4]u8, @bitCast(db_header.signature)))); | 24 | assert(mem.eql(u8, &db_header.signature, "kych")); |
| 25 | 25 | ||
| 26 | try stream.seekTo(db_header.schema_offset); | 26 | try stream.seekTo(db_header.schema_offset); |
| 27 | 27 | ||
| ... | @@ -73,7 +73,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { | ... | @@ -73,7 +73,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator) RescanMacError!void { |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | const ApplDbHeader = extern struct { | 75 | const ApplDbHeader = extern struct { |
| 76 | signature: @Vector(4, u8), | 76 | signature: [4]u8, |
| 77 | version: u32, | 77 | version: u32, |
| 78 | header_size: u32, | 78 | header_size: u32, |
| 79 | schema_offset: u32, | 79 | schema_offset: u32, |
lib/std/crypto/tls/Client.zig+39-12| ... | @@ -452,11 +452,20 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In | ... | @@ -452,11 +452,20 @@ pub fn init(stream: anytype, ca_bundle: Certificate.Bundle, host: []const u8) In |
| 452 | if (ciphertext.len > cleartext_buf.len) return error.TlsRecordOverflow; | 452 | if (ciphertext.len > cleartext_buf.len) return error.TlsRecordOverflow; |
| 453 | const cleartext = cleartext_buf[0..ciphertext.len]; | 453 | const cleartext = cleartext_buf[0..ciphertext.len]; |
| 454 | const auth_tag = record_decoder.array(P.AEAD.tag_length).*; | 454 | const auth_tag = record_decoder.array(P.AEAD.tag_length).*; |
| 455 | const V = @Vector(P.AEAD.nonce_length, u8); | 455 | const nonce = if (builtin.zig_backend == .stage2_x86_64 and |
| 456 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 456 | P.AEAD.nonce_length > comptime std.simd.suggestVectorLength(u8) orelse 1) |
| 457 | const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq))); | 457 | nonce: { |
| 458 | var nonce = p.server_handshake_iv; | ||
| 459 | const operand = std.mem.readInt(u64, nonce[nonce.len - 8 ..], .big); | ||
| 460 | std.mem.writeInt(u64, nonce[nonce.len - 8 ..], operand ^ read_seq, .big); | ||
| 461 | break :nonce nonce; | ||
| 462 | } else nonce: { | ||
| 463 | const V = @Vector(P.AEAD.nonce_length, u8); | ||
| 464 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | ||
| 465 | const operand: V = pad ++ @as([8]u8, @bitCast(big(read_seq))); | ||
| 466 | break :nonce @as(V, p.server_handshake_iv) ^ operand; | ||
| 467 | }; | ||
| 458 | read_seq += 1; | 468 | read_seq += 1; |
| 459 | const nonce = @as(V, p.server_handshake_iv) ^ operand; | ||
| 460 | P.AEAD.decrypt(cleartext, ciphertext, auth_tag, record_header, nonce, p.server_handshake_key) catch | 469 | P.AEAD.decrypt(cleartext, ciphertext, auth_tag, record_header, nonce, p.server_handshake_key) catch |
| 461 | return error.TlsBadRecordMac; | 470 | return error.TlsBadRecordMac; |
| 462 | break :c cleartext; | 471 | break :c cleartext; |
| ... | @@ -806,7 +815,6 @@ fn prepareCiphertextRecord( | ... | @@ -806,7 +815,6 @@ fn prepareCiphertextRecord( |
| 806 | switch (c.application_cipher) { | 815 | switch (c.application_cipher) { |
| 807 | inline else => |*p| { | 816 | inline else => |*p| { |
| 808 | const P = @TypeOf(p.*); | 817 | const P = @TypeOf(p.*); |
| 809 | const V = @Vector(P.AEAD.nonce_length, u8); | ||
| 810 | const overhead_len = tls.record_header_len + P.AEAD.tag_length + 1; | 818 | const overhead_len = tls.record_header_len + P.AEAD.tag_length + 1; |
| 811 | const close_notify_alert_reserved = tls.close_notify_alert.len + overhead_len; | 819 | const close_notify_alert_reserved = tls.close_notify_alert.len + overhead_len; |
| 812 | while (true) { | 820 | while (true) { |
| ... | @@ -838,10 +846,20 @@ fn prepareCiphertextRecord( | ... | @@ -838,10 +846,20 @@ fn prepareCiphertextRecord( |
| 838 | ciphertext_end += ciphertext_len; | 846 | ciphertext_end += ciphertext_len; |
| 839 | const auth_tag = ciphertext_buf[ciphertext_end..][0..P.AEAD.tag_length]; | 847 | const auth_tag = ciphertext_buf[ciphertext_end..][0..P.AEAD.tag_length]; |
| 840 | ciphertext_end += auth_tag.len; | 848 | ciphertext_end += auth_tag.len; |
| 841 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 849 | const nonce = if (builtin.zig_backend == .stage2_x86_64 and |
| 842 | const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq))); | 850 | P.AEAD.nonce_length > comptime std.simd.suggestVectorLength(u8) orelse 1) |
| 851 | nonce: { | ||
| 852 | var nonce = p.client_iv; | ||
| 853 | const operand = std.mem.readInt(u64, nonce[nonce.len - 8 ..], .big); | ||
| 854 | std.mem.writeInt(u64, nonce[nonce.len - 8 ..], operand ^ c.write_seq, .big); | ||
| 855 | break :nonce nonce; | ||
| 856 | } else nonce: { | ||
| 857 | const V = @Vector(P.AEAD.nonce_length, u8); | ||
| 858 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | ||
| 859 | const operand: V = pad ++ @as([8]u8, @bitCast(big(c.write_seq))); | ||
| 860 | break :nonce @as(V, p.client_iv) ^ operand; | ||
| 861 | }; | ||
| 843 | c.write_seq += 1; // TODO send key_update on overflow | 862 | c.write_seq += 1; // TODO send key_update on overflow |
| 844 | const nonce = @as(V, p.client_iv) ^ operand; | ||
| 845 | P.AEAD.encrypt(ciphertext, auth_tag, cleartext, ad, nonce, p.client_key); | 863 | P.AEAD.encrypt(ciphertext, auth_tag, cleartext, ad, nonce, p.client_key); |
| 846 | 864 | ||
| 847 | const record = ciphertext_buf[record_start..ciphertext_end]; | 865 | const record = ciphertext_buf[record_start..ciphertext_end]; |
| ... | @@ -1102,15 +1120,24 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) | ... | @@ -1102,15 +1120,24 @@ pub fn readvAdvanced(c: *Client, stream: anytype, iovecs: []const std.os.iovec) |
| 1102 | const cleartext = switch (c.application_cipher) { | 1120 | const cleartext = switch (c.application_cipher) { |
| 1103 | inline else => |*p| c: { | 1121 | inline else => |*p| c: { |
| 1104 | const P = @TypeOf(p.*); | 1122 | const P = @TypeOf(p.*); |
| 1105 | const V = @Vector(P.AEAD.nonce_length, u8); | ||
| 1106 | const ad = frag[in - 5 ..][0..5]; | 1123 | const ad = frag[in - 5 ..][0..5]; |
| 1107 | const ciphertext_len = record_len - P.AEAD.tag_length; | 1124 | const ciphertext_len = record_len - P.AEAD.tag_length; |
| 1108 | const ciphertext = frag[in..][0..ciphertext_len]; | 1125 | const ciphertext = frag[in..][0..ciphertext_len]; |
| 1109 | in += ciphertext_len; | 1126 | in += ciphertext_len; |
| 1110 | const auth_tag = frag[in..][0..P.AEAD.tag_length].*; | 1127 | const auth_tag = frag[in..][0..P.AEAD.tag_length].*; |
| 1111 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | 1128 | const nonce = if (builtin.zig_backend == .stage2_x86_64 and |
| 1112 | const operand: V = pad ++ @as([8]u8, @bitCast(big(c.read_seq))); | 1129 | P.AEAD.nonce_length > comptime std.simd.suggestVectorLength(u8) orelse 1) |
| 1113 | const nonce: [P.AEAD.nonce_length]u8 = @as(V, p.server_iv) ^ operand; | 1130 | nonce: { |
| 1131 | var nonce = p.server_iv; | ||
| 1132 | const operand = std.mem.readInt(u64, nonce[nonce.len - 8 ..], .big); | ||
| 1133 | std.mem.writeInt(u64, nonce[nonce.len - 8 ..], operand ^ c.read_seq, .big); | ||
| 1134 | break :nonce nonce; | ||
| 1135 | } else nonce: { | ||
| 1136 | const V = @Vector(P.AEAD.nonce_length, u8); | ||
| 1137 | const pad = [1]u8{0} ** (P.AEAD.nonce_length - 8); | ||
| 1138 | const operand: V = pad ++ @as([8]u8, @bitCast(big(c.read_seq))); | ||
| 1139 | break :nonce @as(V, p.server_iv) ^ operand; | ||
| 1140 | }; | ||
| 1114 | const out_buf = vp.peek(); | 1141 | const out_buf = vp.peek(); |
| 1115 | const cleartext_buf = if (ciphertext.len <= out_buf.len) | 1142 | const cleartext_buf = if (ciphertext.len <= out_buf.len) |
| 1116 | out_buf | 1143 | out_buf |
src/Sema.zig+2-1| ... | @@ -20136,6 +20136,7 @@ fn finishStructInit( | ... | @@ -20136,6 +20136,7 @@ fn finishStructInit( |
| 20136 | }, | 20136 | }, |
| 20137 | else => |e| return e, | 20137 | else => |e| return e, |
| 20138 | }; | 20138 | }; |
| 20139 | try sema.resolveStructFieldInits(struct_ty); | ||
| 20139 | try sema.queueFullTypeResolution(struct_ty); | 20140 | try sema.queueFullTypeResolution(struct_ty); |
| 20140 | const struct_val = try block.addAggregateInit(struct_ty, field_inits); | 20141 | const struct_val = try block.addAggregateInit(struct_ty, field_inits); |
| 20141 | return sema.coerce(block, result_ty, struct_val, init_src); | 20142 | return sema.coerce(block, result_ty, struct_val, init_src); |
| ... | @@ -35939,7 +35940,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35939,7 +35940,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void { |
| 35939 | return sema.resolveTypeFully(ty.childType(mod)); | 35940 | return sema.resolveTypeFully(ty.childType(mod)); |
| 35940 | }, | 35941 | }, |
| 35941 | .Struct => switch (mod.intern_pool.indexToKey(ty.toIntern())) { | 35942 | .Struct => switch (mod.intern_pool.indexToKey(ty.toIntern())) { |
| 35942 | .struct_type => return sema.resolveStructFully(ty), | 35943 | .struct_type => try sema.resolveStructFully(ty), |
| 35943 | .anon_struct_type => |tuple| { | 35944 | .anon_struct_type => |tuple| { |
| 35944 | for (tuple.types.get(ip)) |field_ty| { | 35945 | for (tuple.types.get(ip)) |field_ty| { |
| 35945 | try sema.resolveTypeFully(Type.fromInterned(field_ty)); | 35946 | try sema.resolveTypeFully(Type.fromInterned(field_ty)); |
src/TypedValue.zig+8-6| ... | @@ -310,11 +310,6 @@ pub fn print( | ... | @@ -310,11 +310,6 @@ pub fn print( |
| 310 | return writer.writeAll(" }"); | 310 | return writer.writeAll(" }"); |
| 311 | }, | 311 | }, |
| 312 | .ptr => |ptr| { | 312 | .ptr => |ptr| { |
| 313 | if (ptr.addr == .int) {} | ||
| 314 | |||
| 315 | const ptr_ty = ip.indexToKey(ty.toIntern()).ptr_type; | ||
| 316 | if (ptr_ty.flags.size == .Slice) {} | ||
| 317 | |||
| 318 | switch (ptr.addr) { | 313 | switch (ptr.addr) { |
| 319 | .decl => |decl_index| { | 314 | .decl => |decl_index| { |
| 320 | const decl = mod.declPtr(decl_index); | 315 | const decl = mod.declPtr(decl_index); |
| ... | @@ -348,7 +343,14 @@ pub fn print( | ... | @@ -348,7 +343,14 @@ pub fn print( |
| 348 | .val = Value.fromInterned(field_val_ip), | 343 | .val = Value.fromInterned(field_val_ip), |
| 349 | }, writer, level - 1, mod); | 344 | }, writer, level - 1, mod); |
| 350 | }, | 345 | }, |
| 351 | .int => unreachable, | 346 | .int => |int_ip| { |
| 347 | try writer.writeAll("@ptrFromInt("); | ||
| 348 | try print(.{ | ||
| 349 | .ty = Type.usize, | ||
| 350 | .val = Value.fromInterned(int_ip), | ||
| 351 | }, writer, level - 1, mod); | ||
| 352 | try writer.writeByte(')'); | ||
| 353 | }, | ||
| 352 | .eu_payload => |eu_ip| { | 354 | .eu_payload => |eu_ip| { |
| 353 | try writer.writeAll("(payload of "); | 355 | try writer.writeAll("(payload of "); |
| 354 | try print(.{ | 356 | try print(.{ |
src/codegen/llvm/Builder.zig+4-3| ... | @@ -9978,10 +9978,10 @@ fn fnTypeAssumeCapacity( | ... | @@ -9978,10 +9978,10 @@ fn fnTypeAssumeCapacity( |
| 9978 | } | 9978 | } |
| 9979 | pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { | 9979 | pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool { |
| 9980 | const rhs_data = ctx.builder.type_items.items[rhs_index]; | 9980 | const rhs_data = ctx.builder.type_items.items[rhs_index]; |
| 9981 | if (rhs_data.tag != tag) return false; | ||
| 9981 | var rhs_extra = ctx.builder.typeExtraDataTrail(Type.Function, rhs_data.data); | 9982 | var rhs_extra = ctx.builder.typeExtraDataTrail(Type.Function, rhs_data.data); |
| 9982 | const rhs_params = rhs_extra.trail.next(rhs_extra.data.params_len, Type, ctx.builder); | 9983 | const rhs_params = rhs_extra.trail.next(rhs_extra.data.params_len, Type, ctx.builder); |
| 9983 | return rhs_data.tag == tag and lhs_key.ret == rhs_extra.data.ret and | 9984 | return lhs_key.ret == rhs_extra.data.ret and std.mem.eql(Type, lhs_key.params, rhs_params); |
| 9984 | std.mem.eql(Type, lhs_key.params, rhs_params); | ||
| 9985 | } | 9985 | } |
| 9986 | }; | 9986 | }; |
| 9987 | const gop = self.type_map.getOrPutAssumeCapacityAdapted( | 9987 | const gop = self.type_map.getOrPutAssumeCapacityAdapted( |
| ... | @@ -10161,9 +10161,10 @@ fn structTypeAssumeCapacity( | ... | @@ -10161,9 +10161,10 @@ fn structTypeAssumeCapacity( |
| 10161 | } | 10161 | } |
| 10162 | pub fn eql(ctx: @This(), lhs_key: []const Type, _: void, rhs_index: usize) bool { | 10162 | pub fn eql(ctx: @This(), lhs_key: []const Type, _: void, rhs_index: usize) bool { |
| 10163 | const rhs_data = ctx.builder.type_items.items[rhs_index]; | 10163 | const rhs_data = ctx.builder.type_items.items[rhs_index]; |
| 10164 | if (rhs_data.tag != tag) return false; | ||
| 10164 | var rhs_extra = ctx.builder.typeExtraDataTrail(Type.Structure, rhs_data.data); | 10165 | var rhs_extra = ctx.builder.typeExtraDataTrail(Type.Structure, rhs_data.data); |
| 10165 | const rhs_fields = rhs_extra.trail.next(rhs_extra.data.fields_len, Type, ctx.builder); | 10166 | const rhs_fields = rhs_extra.trail.next(rhs_extra.data.fields_len, Type, ctx.builder); |
| 10166 | return rhs_data.tag == tag and std.mem.eql(Type, lhs_key, rhs_fields); | 10167 | return std.mem.eql(Type, lhs_key, rhs_fields); |
| 10167 | } | 10168 | } |
| 10168 | }; | 10169 | }; |
| 10169 | const gop = self.type_map.getOrPutAssumeCapacityAdapted(fields, Adapter{ .builder = self }); | 10170 | const gop = self.type_map.getOrPutAssumeCapacityAdapted(fields, Adapter{ .builder = self }); |