| author | |
| committer | |
| log | ace5714551da16b541d8015e97a2fe32a7a1cf76 |
| tree | 115b330897cc048f554cae530ba23b6d8bce1256 |
| parent | c3d4733a00880e2c757b61b66ba18d9b6753aa11 |
| parent | 8bb58fb4286ad03a243e32e31d67dd2bb5c117ef |
| signature |
32bit glibc fixes12 files changed, 280 insertions(+), 86 deletions(-)
lib/libc/glibc/sysdeps/i386/sysdep.h+3-2| ... | ... | @@ -61,7 +61,7 @@ lose: SYSCALL_PIC_SETUP							 \ |
| 61 | 61 | |
| 62 | 62 | # define SETUP_PIC_REG(reg) \ |
| 63 | 63 | .ifndef GET_PC_THUNK(reg);						 \ |
| 64 | .section .gnu.linkonce.t.GET_PC_THUNK(reg),"ax",@progbits;		 \ | |
| 64 | .section .text.GET_PC_THUNK(reg),"axG",@progbits,GET_PC_THUNK(reg),comdat; \ | |
| 65 | 65 | .globl GET_PC_THUNK(reg);						 \ |
| 66 | 66 | .hidden GET_PC_THUNK(reg);						 \ |
| 67 | 67 | .p2align 4;								 \ |
| ... | ... | @@ -97,8 +97,9 @@ GET_PC_THUNK(reg):							 \ |
| 97 | 97 | |
| 98 | 98 | # define SETUP_PIC_REG_STR(reg)						\ |
| 99 | 99 | ".ifndef " GET_PC_THUNK_STR (reg) "\n"				\ |
| 100 | ".section .gnu.linkonce.t." GET_PC_THUNK_STR (reg) ",\"ax\",@progbits\n" \ | |
| 100 | "section .text." GET_PC_THUNK_STR (reg) ",\"axG\",@progbits," 	\ | |
| 101 | 101 | ".globl " GET_PC_THUNK_STR (reg) "\n"					\ |
| 102 | GET_PC_THUNK_STR (reg) ",comdat\n" \ | |
| 102 | 103 | ".hidden " GET_PC_THUNK_STR (reg) "\n"				\ |
| 103 | 104 | ".p2align 4\n"							\ |
| 104 | 105 | ".type " GET_PC_THUNK_STR (reg) ",@function\n"			\ |
lib/std/c.zig+5-5| ... | ... | @@ -89,13 +89,13 @@ pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int; |
| 89 | 89 | pub extern "c" fn raise(sig: c_int) c_int; |
| 90 | 90 | pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize; |
| 91 | 91 | pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize; |
| 92 | pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize; | |
| 93 | pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: u64) isize; | |
| 92 | pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: off_t) isize; | |
| 93 | pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: off_t) isize; | |
| 94 | 94 | pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize; |
| 95 | pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: u64) isize; | |
| 95 | pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: off_t) isize; | |
| 96 | 96 | pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize; |
| 97 | pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize; | |
| 98 | pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: u64) *c_void; | |
| 97 | pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize; | |
| 98 | pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: off_t) *c_void; | |
| 99 | 99 | pub extern "c" fn munmap(addr: *align(page_size) c_void, len: usize) c_int; |
| 100 | 100 | pub extern "c" fn mprotect(addr: *align(page_size) c_void, len: usize, prot: c_uint) c_int; |
| 101 | 101 | pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: c_int) c_int; |
lib/std/c/linux.zig+17-2| ... | ... | @@ -61,6 +61,23 @@ pub const EAI = extern enum(c_int) { |
| 61 | 61 | _, |
| 62 | 62 | }; |
| 63 | 63 | |
| 64 | pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int; | |
| 65 | pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE; | |
| 66 | pub extern "c" fn fstat64(fd: fd_t, buf: *libc_stat) c_int; | |
| 67 | pub extern "c" fn fstatat64(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int; | |
| 68 | pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int; | |
| 69 | pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int; | |
| 70 | pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64; | |
| 71 | pub extern "c" fn mmap64(addr: ?*align(std.mem.page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: i64) *c_void; | |
| 72 | pub extern "c" fn open64(path: [*:0]const u8, oflag: c_uint, ...) c_int; | |
| 73 | pub extern "c" fn openat64(fd: c_int, path: [*:0]const u8, oflag: c_uint, ...) c_int; | |
| 74 | pub extern "c" fn pread64(fd: fd_t, buf: [*]u8, nbyte: usize, offset: i64) isize; | |
| 75 | pub extern "c" fn preadv64(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: i64) isize; | |
| 76 | pub extern "c" fn pwrite64(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: i64) isize; | |
| 77 | pub extern "c" fn pwritev64(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: i64) isize; | |
| 78 | pub extern "c" fn sendfile64(out_fd: fd_t, in_fd: fd_t, offset: ?*i64, count: usize) isize; | |
| 79 | pub extern "c" fn setrlimit64(resource: rlimit_resource, rlim: *const rlimit) c_int; | |
| 80 | ||
| 64 | 81 | pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize; |
| 65 | 82 | pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int; |
| 66 | 83 | pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int; |
| ... | ... | @@ -90,8 +107,6 @@ pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; |
| 90 | 107 | |
| 91 | 108 | pub extern "c" fn fallocate(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int; |
| 92 | 109 | |
| 93 | pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int; | |
| 94 | ||
| 95 | 110 | pub extern "c" fn sendfile( |
| 96 | 111 | out_fd: fd_t, |
| 97 | 112 | in_fd: fd_t, |
lib/std/fs/file.zig+3-3| ... | ... | @@ -482,7 +482,7 @@ pub const File = struct { |
| 482 | 482 | /// order to handle partial reads from the underlying OS layer. |
| 483 | 483 | /// See https://github.com/ziglang/zig/issues/7699 |
| 484 | 484 | pub fn readvAll(self: File, iovecs: []os.iovec) ReadError!usize { |
| 485 | if (iovecs.len == 0) return; | |
| 485 | if (iovecs.len == 0) return 0; | |
| 486 | 486 | |
| 487 | 487 | var i: usize = 0; |
| 488 | 488 | var off: usize = 0; |
| ... | ... | @@ -524,8 +524,8 @@ pub const File = struct { |
| 524 | 524 | /// The `iovecs` parameter is mutable because this function needs to mutate the fields in |
| 525 | 525 | /// order to handle partial reads from the underlying OS layer. |
| 526 | 526 | /// See https://github.com/ziglang/zig/issues/7699 |
| 527 | pub fn preadvAll(self: File, iovecs: []const os.iovec, offset: u64) PReadError!void { | |
| 528 | if (iovecs.len == 0) return; | |
| 527 | pub fn preadvAll(self: File, iovecs: []os.iovec, offset: u64) PReadError!usize { | |
| 528 | if (iovecs.len == 0) return 0; | |
| 529 | 529 | |
| 530 | 530 | var i: usize = 0; |
| 531 | 531 | var off: usize = 0; |
lib/std/fs/test.zig+83| ... | ... | @@ -520,6 +520,89 @@ test "makePath, put some files in it, deleteTree" { |
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | test "writev, readv" { | |
| 524 | var tmp = tmpDir(.{}); | |
| 525 | defer tmp.cleanup(); | |
| 526 | ||
| 527 | const line1 = "line1\n"; | |
| 528 | const line2 = "line2\n"; | |
| 529 | ||
| 530 | var buf1: [line1.len]u8 = undefined; | |
| 531 | var buf2: [line2.len]u8 = undefined; | |
| 532 | var write_vecs = [_]std.os.iovec_const{ | |
| 533 | .{ | |
| 534 | .iov_base = line1, | |
| 535 | .iov_len = line1.len, | |
| 536 | }, | |
| 537 | .{ | |
| 538 | .iov_base = line2, | |
| 539 | .iov_len = line2.len, | |
| 540 | }, | |
| 541 | }; | |
| 542 | var read_vecs = [_]std.os.iovec{ | |
| 543 | .{ | |
| 544 | .iov_base = &buf2, | |
| 545 | .iov_len = buf2.len, | |
| 546 | }, | |
| 547 | .{ | |
| 548 | .iov_base = &buf1, | |
| 549 | .iov_len = buf1.len, | |
| 550 | }, | |
| 551 | }; | |
| 552 | ||
| 553 | var src_file = try tmp.dir.createFile("test.txt", .{ .read = true }); | |
| 554 | defer src_file.close(); | |
| 555 | ||
| 556 | try src_file.writevAll(&write_vecs); | |
| 557 | try testing.expectEqual(@as(u64, line1.len + line2.len), try src_file.getEndPos()); | |
| 558 | try src_file.seekTo(0); | |
| 559 | const read = try src_file.readvAll(&read_vecs); | |
| 560 | try testing.expectEqual(@as(usize, line1.len + line2.len), read); | |
| 561 | try testing.expectEqualStrings(&buf1, "line2\n"); | |
| 562 | try testing.expectEqualStrings(&buf2, "line1\n"); | |
| 563 | } | |
| 564 | ||
| 565 | test "pwritev, preadv" { | |
| 566 | var tmp = tmpDir(.{}); | |
| 567 | defer tmp.cleanup(); | |
| 568 | ||
| 569 | const line1 = "line1\n"; | |
| 570 | const line2 = "line2\n"; | |
| 571 | ||
| 572 | var buf1: [line1.len]u8 = undefined; | |
| 573 | var buf2: [line2.len]u8 = undefined; | |
| 574 | var write_vecs = [_]std.os.iovec_const{ | |
| 575 | .{ | |
| 576 | .iov_base = line1, | |
| 577 | .iov_len = line1.len, | |
| 578 | }, | |
| 579 | .{ | |
| 580 | .iov_base = line2, | |
| 581 | .iov_len = line2.len, | |
| 582 | }, | |
| 583 | }; | |
| 584 | var read_vecs = [_]std.os.iovec{ | |
| 585 | .{ | |
| 586 | .iov_base = &buf2, | |
| 587 | .iov_len = buf2.len, | |
| 588 | }, | |
| 589 | .{ | |
| 590 | .iov_base = &buf1, | |
| 591 | .iov_len = buf1.len, | |
| 592 | }, | |
| 593 | }; | |
| 594 | ||
| 595 | var src_file = try tmp.dir.createFile("test.txt", .{ .read = true }); | |
| 596 | defer src_file.close(); | |
| 597 | ||
| 598 | try src_file.pwritevAll(&write_vecs, 16); | |
| 599 | try testing.expectEqual(@as(u64, 16 + line1.len + line2.len), try src_file.getEndPos()); | |
| 600 | const read = try src_file.preadvAll(&read_vecs, 16); | |
| 601 | try testing.expectEqual(@as(usize, line1.len + line2.len), read); | |
| 602 | try testing.expectEqualStrings(&buf1, "line2\n"); | |
| 603 | try testing.expectEqualStrings(&buf2, "line1\n"); | |
| 604 | } | |
| 605 | ||
| 523 | 606 | test "access file" { |
| 524 | 607 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 525 | 608 |
lib/std/os.zig+112-27| ... | ... | @@ -497,8 +497,14 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { |
| 497 | 497 | }; |
| 498 | 498 | const adjusted_len = math.min(max_count, buf.len); |
| 499 | 499 | |
| 500 | const pread_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 501 | system.pread64 | |
| 502 | else | |
| 503 | system.pread; | |
| 504 | ||
| 505 | const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 500 | 506 | while (true) { |
| 501 | const rc = system.pread(fd, buf.ptr, adjusted_len, offset); | |
| 507 | const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset); | |
| 502 | 508 | switch (errno(rc)) { |
| 503 | 509 | 0 => return @intCast(usize, rc), |
| 504 | 510 | EINTR => continue, |
| ... | ... | @@ -567,15 +573,13 @@ pub fn ftruncate(fd: fd_t, length: u64) TruncateError!void { |
| 567 | 573 | } |
| 568 | 574 | |
| 569 | 575 | while (true) { |
| 570 | const rc = if (builtin.link_libc) | |
| 571 | if (std.Target.current.os.tag == .linux) | |
| 572 | system.ftruncate64(fd, @bitCast(off_t, length)) | |
| 573 | else | |
| 574 | system.ftruncate(fd, @bitCast(off_t, length)) | |
| 576 | const ftruncate_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 577 | system.ftruncate64 | |
| 575 | 578 | else |
| 576 | system.ftruncate(fd, length); | |
| 579 | system.ftruncate; | |
| 577 | 580 | |
| 578 | switch (errno(rc)) { | |
| 581 | const ilen = @bitCast(i64, length); // the OS treats this as unsigned | |
| 582 | switch (errno(ftruncate_sym(fd, ilen))) { | |
| 579 | 583 | 0 => return, |
| 580 | 584 | EINTR => continue, |
| 581 | 585 | EFBIG => return error.FileTooBig, |
| ... | ... | @@ -637,8 +641,14 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { |
| 637 | 641 | |
| 638 | 642 | const iov_count = math.cast(u31, iov.len) catch math.maxInt(u31); |
| 639 | 643 | |
| 644 | const preadv_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 645 | system.preadv64 | |
| 646 | else | |
| 647 | system.preadv; | |
| 648 | ||
| 649 | const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 640 | 650 | while (true) { |
| 641 | const rc = system.preadv(fd, iov.ptr, iov_count, offset); | |
| 651 | const rc = preadv_sym(fd, iov.ptr, iov_count, ioffset); | |
| 642 | 652 | switch (errno(rc)) { |
| 643 | 653 | 0 => return @bitCast(usize, rc), |
| 644 | 654 | EINTR => continue, |
| ... | ... | @@ -895,8 +905,14 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { |
| 895 | 905 | }; |
| 896 | 906 | const adjusted_len = math.min(max_count, bytes.len); |
| 897 | 907 | |
| 908 | const pwrite_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 909 | system.pwrite64 | |
| 910 | else | |
| 911 | system.pwrite; | |
| 912 | ||
| 913 | const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 898 | 914 | while (true) { |
| 899 | const rc = system.pwrite(fd, bytes.ptr, adjusted_len, offset); | |
| 915 | const rc = pwrite_sym(fd, bytes.ptr, adjusted_len, ioffset); | |
| 900 | 916 | switch (errno(rc)) { |
| 901 | 917 | 0 => return @intCast(usize, rc), |
| 902 | 918 | EINTR => continue, |
| ... | ... | @@ -977,9 +993,15 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz |
| 977 | 993 | } |
| 978 | 994 | } |
| 979 | 995 | |
| 996 | const pwritev_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 997 | system.pwritev64 | |
| 998 | else | |
| 999 | system.pwritev; | |
| 1000 | ||
| 980 | 1001 | const iov_count = math.cast(u31, iov.len) catch math.maxInt(u31); |
| 1002 | const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 981 | 1003 | while (true) { |
| 982 | const rc = system.pwritev(fd, iov.ptr, iov_count, offset); | |
| 1004 | const rc = pwritev_sym(fd, iov.ptr, iov_count, ioffset); | |
| 983 | 1005 | switch (errno(rc)) { |
| 984 | 1006 | 0 => return @intCast(usize, rc), |
| 985 | 1007 | EINTR => continue, |
| ... | ... | @@ -1068,8 +1090,14 @@ pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: mode_t) OpenError!fd_t |
| 1068 | 1090 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1069 | 1091 | return openW(file_path_w.span(), flags, perm); |
| 1070 | 1092 | } |
| 1093 | ||
| 1094 | const open_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 1095 | system.open64 | |
| 1096 | else | |
| 1097 | system.open; | |
| 1098 | ||
| 1071 | 1099 | while (true) { |
| 1072 | const rc = system.open(file_path, flags, perm); | |
| 1100 | const rc = open_sym(file_path, flags, perm); | |
| 1073 | 1101 | switch (errno(rc)) { |
| 1074 | 1102 | 0 => return @intCast(fd_t, rc), |
| 1075 | 1103 | EINTR => continue, |
| ... | ... | @@ -1202,8 +1230,14 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) |
| 1202 | 1230 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1203 | 1231 | return openatW(dir_fd, file_path_w.span(), flags, mode); |
| 1204 | 1232 | } |
| 1233 | ||
| 1234 | const openat_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 1235 | system.openat64 | |
| 1236 | else | |
| 1237 | system.openat; | |
| 1238 | ||
| 1205 | 1239 | while (true) { |
| 1206 | const rc = system.openat(dir_fd, file_path, flags, mode); | |
| 1240 | const rc = openat_sym(dir_fd, file_path, flags, mode); | |
| 1207 | 1241 | switch (errno(rc)) { |
| 1208 | 1242 | 0 => return @intCast(fd_t, rc), |
| 1209 | 1243 | EINTR => continue, |
| ... | ... | @@ -3437,8 +3471,13 @@ pub fn fstat(fd: fd_t) FStatError!Stat { |
| 3437 | 3471 | @compileError("fstat is not yet implemented on Windows"); |
| 3438 | 3472 | } |
| 3439 | 3473 | |
| 3474 | const fstat_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 3475 | system.fstat64 | |
| 3476 | else | |
| 3477 | system.fstat; | |
| 3478 | ||
| 3440 | 3479 | var stat = mem.zeroes(Stat); |
| 3441 | switch (errno(system.fstat(fd, &stat))) { | |
| 3480 | switch (errno(fstat_sym(fd, &stat))) { | |
| 3442 | 3481 | 0 => return stat, |
| 3443 | 3482 | EINVAL => unreachable, |
| 3444 | 3483 | EBADF => unreachable, // Always a race condition. |
| ... | ... | @@ -3488,8 +3527,13 @@ pub fn fstatatWasi(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError!S |
| 3488 | 3527 | /// Same as `fstatat` but `pathname` is null-terminated. |
| 3489 | 3528 | /// See also `fstatat`. |
| 3490 | 3529 | pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat { |
| 3530 | const fstatat_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 3531 | system.fstatat64 | |
| 3532 | else | |
| 3533 | system.fstatat; | |
| 3534 | ||
| 3491 | 3535 | var stat = mem.zeroes(Stat); |
| 3492 | switch (errno(system.fstatat(dirfd, pathname, &stat, flags))) { | |
| 3536 | switch (errno(fstatat_sym(dirfd, pathname, &stat, flags))) { | |
| 3493 | 3537 | 0 => return stat, |
| 3494 | 3538 | EINVAL => unreachable, |
| 3495 | 3539 | EBADF => unreachable, // Always a race condition. |
| ... | ... | @@ -3701,12 +3745,17 @@ pub fn mmap( |
| 3701 | 3745 | fd: fd_t, |
| 3702 | 3746 | offset: u64, |
| 3703 | 3747 | ) MMapError![]align(mem.page_size) u8 { |
| 3748 | const mmap_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 3749 | system.mmap64 | |
| 3750 | else | |
| 3751 | system.mmap; | |
| 3752 | ||
| 3753 | const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 3754 | const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset); | |
| 3704 | 3755 | const err = if (builtin.link_libc) blk: { |
| 3705 | const rc = std.c.mmap(ptr, length, prot, flags, fd, offset); | |
| 3706 | 3756 | if (rc != std.c.MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length]; |
| 3707 | 3757 | break :blk system._errno().*; |
| 3708 | 3758 | } else blk: { |
| 3709 | const rc = system.mmap(ptr, length, prot, flags, fd, offset); | |
| 3710 | 3759 | const err = errno(rc); |
| 3711 | 3760 | if (err == 0) return @intToPtr([*]align(mem.page_size) u8, rc)[0..length]; |
| 3712 | 3761 | break :blk err; |
| ... | ... | @@ -4056,8 +4105,14 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void { |
| 4056 | 4105 | else => |err| return unexpectedErrno(err), |
| 4057 | 4106 | } |
| 4058 | 4107 | } |
| 4059 | const ipos = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 4060 | switch (errno(system.lseek(fd, ipos, SEEK_SET))) { | |
| 4108 | ||
| 4109 | const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 4110 | system.lseek64 | |
| 4111 | else | |
| 4112 | system.lseek; | |
| 4113 | ||
| 4114 | const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 4115 | switch (errno(lseek_sym(fd, ioffset, SEEK_SET))) { | |
| 4061 | 4116 | 0 => return, |
| 4062 | 4117 | EBADF => unreachable, // always a race condition |
| 4063 | 4118 | EINVAL => return error.Unseekable, |
| ... | ... | @@ -4098,7 +4153,13 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void { |
| 4098 | 4153 | else => |err| return unexpectedErrno(err), |
| 4099 | 4154 | } |
| 4100 | 4155 | } |
| 4101 | switch (errno(system.lseek(fd, offset, SEEK_CUR))) { | |
| 4156 | const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 4157 | system.lseek64 | |
| 4158 | else | |
| 4159 | system.lseek; | |
| 4160 | ||
| 4161 | const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 4162 | switch (errno(lseek_sym(fd, ioffset, SEEK_CUR))) { | |
| 4102 | 4163 | 0 => return, |
| 4103 | 4164 | EBADF => unreachable, // always a race condition |
| 4104 | 4165 | EINVAL => return error.Unseekable, |
| ... | ... | @@ -4139,7 +4200,13 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void { |
| 4139 | 4200 | else => |err| return unexpectedErrno(err), |
| 4140 | 4201 | } |
| 4141 | 4202 | } |
| 4142 | switch (errno(system.lseek(fd, offset, SEEK_END))) { | |
| 4203 | const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 4204 | system.lseek64 | |
| 4205 | else | |
| 4206 | system.lseek; | |
| 4207 | ||
| 4208 | const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned | |
| 4209 | switch (errno(lseek_sym(fd, ioffset, SEEK_END))) { | |
| 4143 | 4210 | 0 => return, |
| 4144 | 4211 | EBADF => unreachable, // always a race condition |
| 4145 | 4212 | EINVAL => return error.Unseekable, |
| ... | ... | @@ -4180,7 +4247,12 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 { |
| 4180 | 4247 | else => |err| return unexpectedErrno(err), |
| 4181 | 4248 | } |
| 4182 | 4249 | } |
| 4183 | const rc = system.lseek(fd, 0, SEEK_CUR); | |
| 4250 | const lseek_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 4251 | system.lseek64 | |
| 4252 | else | |
| 4253 | system.lseek; | |
| 4254 | ||
| 4255 | const rc = lseek_sym(fd, 0, SEEK_CUR); | |
| 4184 | 4256 | switch (errno(rc)) { |
| 4185 | 4257 | 0 => return @bitCast(u64, rc), |
| 4186 | 4258 | EBADF => unreachable, // always a race condition |
| ... | ... | @@ -5198,9 +5270,14 @@ pub fn sendfile( |
| 5198 | 5270 | // Here we match BSD behavior, making a zero count value send as many bytes as possible. |
| 5199 | 5271 | const adjusted_count = if (in_len == 0) max_count else math.min(in_len, @as(size_t, max_count)); |
| 5200 | 5272 | |
| 5273 | const sendfile_sym = if (builtin.link_libc) | |
| 5274 | system.sendfile64 | |
| 5275 | else | |
| 5276 | system.sendfile; | |
| 5277 | ||
| 5201 | 5278 | while (true) { |
| 5202 | 5279 | var offset: off_t = @bitCast(off_t, in_offset); |
| 5203 | const rc = system.sendfile(out_fd, in_fd, &offset, adjusted_count); | |
| 5280 | const rc = sendfile_sym(out_fd, in_fd, &offset, adjusted_count); | |
| 5204 | 5281 | switch (errno(rc)) { |
| 5205 | 5282 | 0 => { |
| 5206 | 5283 | const amt = @bitCast(usize, rc); |
| ... | ... | @@ -6018,9 +6095,13 @@ pub fn prctl(option: PR, args: anytype) PrctlError!u31 { |
| 6018 | 6095 | pub const GetrlimitError = UnexpectedError; |
| 6019 | 6096 | |
| 6020 | 6097 | pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { |
| 6098 | const getrlimit_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 6099 | system.getrlimit64 | |
| 6100 | else | |
| 6101 | system.getrlimit; | |
| 6102 | ||
| 6021 | 6103 | var limits: rlimit = undefined; |
| 6022 | const rc = system.getrlimit(resource, &limits); | |
| 6023 | switch (errno(rc)) { | |
| 6104 | switch (errno(getrlimit_sym(resource, &limits))) { | |
| 6024 | 6105 | 0 => return limits, |
| 6025 | 6106 | EFAULT => unreachable, // bogus pointer |
| 6026 | 6107 | EINVAL => unreachable, |
| ... | ... | @@ -6031,8 +6112,12 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { |
| 6031 | 6112 | pub const SetrlimitError = error{PermissionDenied} || UnexpectedError; |
| 6032 | 6113 | |
| 6033 | 6114 | pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void { |
| 6034 | const rc = system.setrlimit(resource, &limits); | |
| 6035 | switch (errno(rc)) { | |
| 6115 | const setrlimit_sym = if (builtin.os.tag == .linux and builtin.link_libc) | |
| 6116 | system.setrlimit64 | |
| 6117 | else | |
| 6118 | system.setrlimit; | |
| 6119 | ||
| 6120 | switch (errno(setrlimit_sym(resource, &limits))) { | |
| 6036 | 6121 | 0 => return, |
| 6037 | 6122 | EFAULT => unreachable, // bogus pointer |
| 6038 | 6123 | EINVAL => unreachable, |
lib/std/os/linux.zig+39-24| ... | ... | @@ -59,15 +59,30 @@ const require_aligned_register_pair = |
| 59 | 59 | std.Target.current.cpu.arch.isThumb(); |
| 60 | 60 | |
| 61 | 61 | // Split a 64bit value into a {LSB,MSB} pair. |
| 62 | fn splitValue64(val: u64) [2]u32 { | |
| 62 | // The LE/BE variants specify the endianness to assume. | |
| 63 | fn splitValueLE64(val: i64) [2]u32 { | |
| 64 | const u = @bitCast(u64, val); | |
| 65 | return [2]u32{ | |
| 66 | @truncate(u32, u), | |
| 67 | @truncate(u32, u >> 32), | |
| 68 | }; | |
| 69 | } | |
| 70 | fn splitValueBE64(val: i64) [2]u32 { | |
| 71 | return [2]u32{ | |
| 72 | @truncate(u32, u >> 32), | |
| 73 | @truncate(u32, u), | |
| 74 | }; | |
| 75 | } | |
| 76 | fn splitValue64(val: i64) [2]u32 { | |
| 77 | const u = @bitCast(u64, val); | |
| 63 | 78 | switch (builtin.endian) { |
| 64 | 79 | .Little => return [2]u32{ |
| 65 | @truncate(u32, val), | |
| 66 | @truncate(u32, val >> 32), | |
| 80 | @truncate(u32, u), | |
| 81 | @truncate(u32, u >> 32), | |
| 67 | 82 | }, |
| 68 | 83 | .Big => return [2]u32{ |
| 69 | @truncate(u32, val >> 32), | |
| 70 | @truncate(u32, val), | |
| 84 | @truncate(u32, u >> 32), | |
| 85 | @truncate(u32, u), | |
| 71 | 86 | }, |
| 72 | 87 | } |
| 73 | 88 | } |
| ... | ... | @@ -141,8 +156,8 @@ pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, fl |
| 141 | 156 | return syscall4(.utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags); |
| 142 | 157 | } |
| 143 | 158 | |
| 144 | pub fn fallocate(fd: i32, mode: i32, offset: u64, length: u64) usize { | |
| 145 | if (@sizeOf(usize) == 4) { | |
| 159 | pub fn fallocate(fd: i32, mode: i32, offset: i64, length: i64) usize { | |
| 160 | if (usize_bits < 64) { | |
| 146 | 161 | const offset_halves = splitValue64(offset); |
| 147 | 162 | const length_halves = splitValue64(length); |
| 148 | 163 | return syscall6( |
| ... | ... | @@ -159,8 +174,8 @@ pub fn fallocate(fd: i32, mode: i32, offset: u64, length: u64) usize { |
| 159 | 174 | .fallocate, |
| 160 | 175 | @bitCast(usize, @as(isize, fd)), |
| 161 | 176 | @bitCast(usize, @as(isize, mode)), |
| 162 | offset, | |
| 163 | length, | |
| 177 | @bitCast(u64, offset), | |
| 178 | @bitCast(u64, length), | |
| 164 | 179 | ); |
| 165 | 180 | } |
| 166 | 181 | } |
| ... | ... | @@ -243,7 +258,7 @@ pub fn umount2(special: [*:0]const u8, flags: u32) usize { |
| 243 | 258 | return syscall2(.umount2, @ptrToInt(special), flags); |
| 244 | 259 | } |
| 245 | 260 | |
| 246 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize { | |
| 261 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: i64) usize { | |
| 247 | 262 | if (@hasField(SYS, "mmap2")) { |
| 248 | 263 | // Make sure the offset is also specified in multiples of page size |
| 249 | 264 | if ((offset & (MMAP2_UNIT - 1)) != 0) |
| ... | ... | @@ -256,7 +271,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 256 | 271 | prot, |
| 257 | 272 | flags, |
| 258 | 273 | @bitCast(usize, @as(isize, fd)), |
| 259 | @truncate(usize, offset / MMAP2_UNIT), | |
| 274 | @truncate(usize, @bitCast(u64, offset) / MMAP2_UNIT), | |
| 260 | 275 | ); |
| 261 | 276 | } else { |
| 262 | 277 | return syscall6( |
| ... | ... | @@ -266,7 +281,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 266 | 281 | prot, |
| 267 | 282 | flags, |
| 268 | 283 | @bitCast(usize, @as(isize, fd)), |
| 269 | offset, | |
| 284 | @bitCast(u64, offset), | |
| 270 | 285 | ); |
| 271 | 286 | } |
| 272 | 287 | } |
| ... | ... | @@ -308,8 +323,8 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize { |
| 308 | 323 | return syscall3(.read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); |
| 309 | 324 | } |
| 310 | 325 | |
| 311 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { | |
| 312 | const offset_halves = splitValue64(offset); | |
| 326 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: i64) usize { | |
| 327 | const offset_halves = splitValueLE64(offset); | |
| 313 | 328 | return syscall5( |
| 314 | 329 | .preadv, |
| 315 | 330 | @bitCast(usize, @as(isize, fd)), |
| ... | ... | @@ -320,7 +335,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { |
| 320 | 335 | ); |
| 321 | 336 | } |
| 322 | 337 | |
| 323 | pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize { | |
| 338 | pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: i64, flags: kernel_rwf) usize { | |
| 324 | 339 | const offset_halves = splitValue64(offset); |
| 325 | 340 | return syscall6( |
| 326 | 341 | .preadv2, |
| ... | ... | @@ -341,8 +356,8 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { |
| 341 | 356 | return syscall3(.writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); |
| 342 | 357 | } |
| 343 | 358 | |
| 344 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { | |
| 345 | const offset_halves = splitValue64(offset); | |
| 359 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64) usize { | |
| 360 | const offset_halves = splitValueLE64(offset); | |
| 346 | 361 | return syscall5( |
| 347 | 362 | .pwritev, |
| 348 | 363 | @bitCast(usize, @as(isize, fd)), |
| ... | ... | @@ -353,7 +368,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us |
| 353 | 368 | ); |
| 354 | 369 | } |
| 355 | 370 | |
| 356 | pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize { | |
| 371 | pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: i64, flags: kernel_rwf) usize { | |
| 357 | 372 | const offset_halves = splitValue64(offset); |
| 358 | 373 | return syscall6( |
| 359 | 374 | .pwritev2, |
| ... | ... | @@ -386,7 +401,7 @@ pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) us |
| 386 | 401 | return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath)); |
| 387 | 402 | } |
| 388 | 403 | |
| 389 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { | |
| 404 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: i64) usize { | |
| 390 | 405 | if (@hasField(SYS, "pread64") and usize_bits < 64) { |
| 391 | 406 | const offset_halves = splitValue64(offset); |
| 392 | 407 | if (require_aligned_register_pair) { |
| ... | ... | @@ -417,7 +432,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { |
| 417 | 432 | @bitCast(usize, @as(isize, fd)), |
| 418 | 433 | @ptrToInt(buf), |
| 419 | 434 | count, |
| 420 | offset, | |
| 435 | @bitCast(u64, offset), | |
| 421 | 436 | ); |
| 422 | 437 | } |
| 423 | 438 | } |
| ... | ... | @@ -452,7 +467,7 @@ pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { |
| 452 | 467 | return syscall3(.write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); |
| 453 | 468 | } |
| 454 | 469 | |
| 455 | pub fn ftruncate(fd: i32, length: u64) usize { | |
| 470 | pub fn ftruncate(fd: i32, length: i64) usize { | |
| 456 | 471 | if (@hasField(SYS, "ftruncate64") and usize_bits < 64) { |
| 457 | 472 | const length_halves = splitValue64(length); |
| 458 | 473 | if (require_aligned_register_pair) { |
| ... | ... | @@ -475,12 +490,12 @@ pub fn ftruncate(fd: i32, length: u64) usize { |
| 475 | 490 | return syscall2( |
| 476 | 491 | .ftruncate, |
| 477 | 492 | @bitCast(usize, @as(isize, fd)), |
| 478 | @truncate(usize, length), | |
| 493 | @bitCast(usize, length), | |
| 479 | 494 | ); |
| 480 | 495 | } |
| 481 | 496 | } |
| 482 | 497 | |
| 483 | pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize { | |
| 498 | pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: i64) usize { | |
| 484 | 499 | if (@hasField(SYS, "pwrite64") and usize_bits < 64) { |
| 485 | 500 | const offset_halves = splitValue64(offset); |
| 486 | 501 | |
| ... | ... | @@ -512,7 +527,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: u64) usize { |
| 512 | 527 | @bitCast(usize, @as(isize, fd)), |
| 513 | 528 | @ptrToInt(buf), |
| 514 | 529 | count, |
| 515 | offset, | |
| 530 | @bitCast(u64, offset), | |
| 516 | 531 | ); |
| 517 | 532 | } |
| 518 | 533 | } |
lib/std/os/linux/test.zig+1-1| ... | ... | @@ -20,7 +20,7 @@ test "fallocate" { |
| 20 | 20 | |
| 21 | 21 | try expect((try file.stat()).size == 0); |
| 22 | 22 | |
| 23 | const len: u64 = 65536; | |
| 23 | const len: i64 = 65536; | |
| 24 | 24 | switch (linux.getErrno(linux.fallocate(file.handle, 0, 0, len))) { |
| 25 | 25 | 0 => {}, |
| 26 | 26 | linux.ENOSYS => return error.SkipZigTest, |
lib/std/special/c.zig+2-2| ... | ... | @@ -225,7 +225,7 @@ export fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.C) ?[*]u8 |
| 225 | 225 | return dest; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | export fn memcmp(vl: ?[*]const u8, vr: ?[*]const u8, n: usize) callconv(.C) isize { | |
| 228 | export fn memcmp(vl: ?[*]const u8, vr: ?[*]const u8, n: usize) callconv(.C) c_int { | |
| 229 | 229 | @setRuntimeSafety(false); |
| 230 | 230 | |
| 231 | 231 | var index: usize = 0; |
| ... | ... | @@ -250,7 +250,7 @@ test "memcmp" { |
| 250 | 250 | try std.testing.expect(memcmp(base_arr[0..], arr3[0..], base_arr.len) < 0); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) isize { | |
| 253 | export fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.C) c_int { | |
| 254 | 254 | @setRuntimeSafety(false); |
| 255 | 255 | |
| 256 | 256 | var index: usize = 0; |
src/glibc.zig+2-1| ... | ... | @@ -40,10 +40,11 @@ pub const ABI = struct { |
| 40 | 40 | } |
| 41 | 41 | }; |
| 42 | 42 | |
| 43 | // The order of the elements in this array defines the linking order. | |
| 43 | 44 | pub const libs = [_]Lib{ |
| 44 | .{ .name = "c", .sover = 6 }, | |
| 45 | 45 | .{ .name = "m", .sover = 6 }, |
| 46 | 46 | .{ .name = "pthread", .sover = 0 }, |
| 47 | .{ .name = "c", .sover = 6 }, | |
| 47 | 48 | .{ .name = "dl", .sover = 2 }, |
| 48 | 49 | .{ .name = "rt", .sover = 1 }, |
| 49 | 50 | .{ .name = "ld", .sover = 2 }, |
src/link/Elf.zig+5-10| ... | ... | @@ -1648,17 +1648,12 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1648 | 1648 | // libc dep |
| 1649 | 1649 | if (self.base.options.link_libc) { |
| 1650 | 1650 | if (self.base.options.libc_installation != null) { |
| 1651 | if (self.base.options.link_mode == .Static) { | |
| 1652 | try argv.append("--start-group"); | |
| 1653 | try argv.append("-lc"); | |
| 1654 | try argv.append("-lm"); | |
| 1655 | try argv.append("--end-group"); | |
| 1656 | } else { | |
| 1657 | try argv.append("-lc"); | |
| 1658 | try argv.append("-lm"); | |
| 1659 | } | |
| 1660 | ||
| 1651 | const needs_grouping = self.base.options.link_mode == .Static; | |
| 1652 | if (needs_grouping) try argv.append("--start-group"); | |
| 1653 | try argv.append("-lm"); | |
| 1661 | 1654 | try argv.append("-lpthread"); |
| 1655 | try argv.append("-lc"); | |
| 1656 | if (needs_grouping) try argv.append("--end-group"); | |
| 1662 | 1657 | } else if (target.isGnuLibC()) { |
| 1663 | 1658 | try argv.append(comp.libunwind_static_lib.?.full_object_path); |
| 1664 | 1659 | for (glibc.libs) |lib| { |
test/tests.zig+8-9| ... | ... | @@ -98,15 +98,14 @@ const test_targets = blk: { |
| 98 | 98 | }, |
| 99 | 99 | .link_libc = true, |
| 100 | 100 | }, |
| 101 | // https://github.com/ziglang/zig/issues/4926 | |
| 102 | //TestTarget{ | |
| 103 | // .target = .{ | |
| 104 | // .cpu_arch = .i386, | |
| 105 | // .os_tag = .linux, | |
| 106 | // .abi = .gnu, | |
| 107 | // }, | |
| 108 | // .link_libc = true, | |
| 109 | //}, | |
| 101 | TestTarget{ | |
| 102 | .target = .{ | |
| 103 | .cpu_arch = .i386, | |
| 104 | .os_tag = .linux, | |
| 105 | .abi = .gnu, | |
| 106 | }, | |
| 107 | .link_libc = true, | |
| 108 | }, | |
| 110 | 109 | |
| 111 | 110 | TestTarget{ |
| 112 | 111 | .target = .{ |