| author | |
| committer | |
| log | d40c4e7c896c5dfed9dd35e8c0d2117f7cf5c53c |
| tree | 07f7204287159ca5c9926e797144ef91ab35cdb6 |
| parent | 5b84192f07d5e4b3f5ebcd3e08d79852710c04f4 |
| parent | 2d2734172484871eb56705e77acca50a8c83d8ae |
| signature |
initial arm64 support 16 files changed, 713 insertions(+), 86 deletions(-)
CMakeLists.txt+1| ... | ... | @@ -578,6 +578,7 @@ set(ZIG_STD_FILES |
| 578 | 578 | "os/linux/index.zig" |
| 579 | 579 | "os/linux/vdso.zig" |
| 580 | 580 | "os/linux/x86_64.zig" |
| 581 | "os/linux/arm64.zig" | |
| 581 | 582 | "os/path.zig" |
| 582 | 583 | "os/time.zig" |
| 583 | 584 | "os/windows/advapi32.zig" |
src-self-hosted/libc_installation.zig+2-2| ... | ... | @@ -280,7 +280,7 @@ pub const LibCInstallation = struct { |
| 280 | 280 | switch (builtin.arch) { |
| 281 | 281 | builtin.Arch.i386 => try stream.write("x86"), |
| 282 | 282 | builtin.Arch.x86_64 => try stream.write("x64"), |
| 283 | builtin.Arch.aarch64 => try stream.write("arm"), | |
| 283 | builtin.Arch.aarch64v8 => try stream.write("arm"), | |
| 284 | 284 | else => return error.UnsupportedArchitecture, |
| 285 | 285 | } |
| 286 | 286 | const ucrt_lib_path = try std.os.path.join(loop.allocator, result_buf.toSliceConst(), "ucrt.lib"); |
| ... | ... | @@ -355,7 +355,7 @@ pub const LibCInstallation = struct { |
| 355 | 355 | switch (builtin.arch) { |
| 356 | 356 | builtin.Arch.i386 => try stream.write("x86\\"), |
| 357 | 357 | builtin.Arch.x86_64 => try stream.write("x64\\"), |
| 358 | builtin.Arch.aarch64 => try stream.write("arm\\"), | |
| 358 | builtin.Arch.aarch64v8 => try stream.write("arm\\"), | |
| 359 | 359 | else => return error.UnsupportedArchitecture, |
| 360 | 360 | } |
| 361 | 361 | const kernel32_path = try std.os.path.join(loop.allocator, result_buf.toSliceConst(), "kernel32.lib"); |
src-self-hosted/link.zig+2-2| ... | ... | @@ -330,7 +330,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 330 | 330 | switch (ctx.comp.target.getArch()) { |
| 331 | 331 | builtin.Arch.i386 => try ctx.args.append(c"-MACHINE:X86"), |
| 332 | 332 | builtin.Arch.x86_64 => try ctx.args.append(c"-MACHINE:X64"), |
| 333 | builtin.Arch.aarch64 => try ctx.args.append(c"-MACHINE:ARM"), | |
| 333 | builtin.Arch.aarch64v8 => try ctx.args.append(c"-MACHINE:ARM"), | |
| 334 | 334 | else => return error.UnsupportedLinkArchitecture, |
| 335 | 335 | } |
| 336 | 336 | |
| ... | ... | @@ -556,7 +556,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 556 | 556 | } |
| 557 | 557 | }, |
| 558 | 558 | DarwinPlatform.Kind.IPhoneOS => { |
| 559 | if (ctx.comp.target.getArch() == builtin.Arch.aarch64) { | |
| 559 | if (ctx.comp.target.getArch() == builtin.Arch.aarch64v8) { | |
| 560 | 560 | // iOS does not need any crt1 files for arm64 |
| 561 | 561 | } else if (platform.versionLessThan(3, 1)) { |
| 562 | 562 | try ctx.args.append(c"-lcrt1.o"); |
src-self-hosted/target.zig+39-5| ... | ... | @@ -250,8 +250,20 @@ pub const Target = union(enum) { |
| 250 | 250 | builtin.Arch.renderscript32, |
| 251 | 251 | => return 32, |
| 252 | 252 | |
| 253 | builtin.Arch.aarch64, | |
| 254 | builtin.Arch.aarch64_be, | |
| 253 | builtin.Arch.aarch64v8_3a, | |
| 254 | builtin.Arch.aarch64v8_2a, | |
| 255 | builtin.Arch.aarch64v8_1a, | |
| 256 | builtin.Arch.aarch64v8, | |
| 257 | builtin.Arch.aarch64v8r, | |
| 258 | builtin.Arch.aarch64v8m_baseline, | |
| 259 | builtin.Arch.aarch64v8m_mainline, | |
| 260 | builtin.Arch.aarch64_bev8_3a, | |
| 261 | builtin.Arch.aarch64_bev8_2a, | |
| 262 | builtin.Arch.aarch64_bev8_1a, | |
| 263 | builtin.Arch.aarch64_bev8, | |
| 264 | builtin.Arch.aarch64_bev8r, | |
| 265 | builtin.Arch.aarch64_bev8m_baseline, | |
| 266 | builtin.Arch.aarch64_bev8m_mainline, | |
| 255 | 267 | builtin.Arch.mips64, |
| 256 | 268 | builtin.Arch.mips64el, |
| 257 | 269 | builtin.Arch.powerpc64, |
| ... | ... | @@ -316,8 +328,23 @@ pub const Target = union(enum) { |
| 316 | 328 | builtin.Arch.sparcel, |
| 317 | 329 | => return "/lib/ld-linux.so.2", |
| 318 | 330 | |
| 319 | builtin.Arch.aarch64 => return "/lib/ld-linux-aarch64.so.1", | |
| 320 | builtin.Arch.aarch64_be => return "/lib/ld-linux-aarch64_be.so.1", | |
| 331 | builtin.Arch.aarch64v8_3a, | |
| 332 | builtin.Arch.aarch64v8_2a, | |
| 333 | builtin.Arch.aarch64v8_1a, | |
| 334 | builtin.Arch.aarch64v8, | |
| 335 | builtin.Arch.aarch64v8r, | |
| 336 | builtin.Arch.aarch64v8m_baseline, | |
| 337 | builtin.Arch.aarch64v8m_mainline, | |
| 338 | => return "/lib/ld-linux-aarch64.so.1", | |
| 339 | ||
| 340 | builtin.Arch.aarch64_bev8_3a, | |
| 341 | builtin.Arch.aarch64_bev8_2a, | |
| 342 | builtin.Arch.aarch64_bev8_1a, | |
| 343 | builtin.Arch.aarch64_bev8, | |
| 344 | builtin.Arch.aarch64_bev8r, | |
| 345 | builtin.Arch.aarch64_bev8m_baseline, | |
| 346 | builtin.Arch.aarch64_bev8m_mainline, | |
| 347 | => return "/lib/ld-linux-aarch64_be.so.1", | |
| 321 | 348 | |
| 322 | 349 | builtin.Arch.armv8_3a, |
| 323 | 350 | builtin.Arch.armv8_2a, |
| ... | ... | @@ -530,7 +557,14 @@ pub const Target = union(enum) { |
| 530 | 557 | pub fn getDarwinArchString(self: Target) []const u8 { |
| 531 | 558 | const arch = self.getArch(); |
| 532 | 559 | switch (arch) { |
| 533 | builtin.Arch.aarch64 => return "arm64", | |
| 560 | builtin.Arch.aarch64v8_3a, | |
| 561 | builtin.Arch.aarch64v8_2a, | |
| 562 | builtin.Arch.aarch64v8_1a, | |
| 563 | builtin.Arch.aarch64v8, | |
| 564 | builtin.Arch.aarch64v8r, | |
| 565 | builtin.Arch.aarch64v8m_baseline, | |
| 566 | builtin.Arch.aarch64v8m_mainline, | |
| 567 | => return "arm64", | |
| 534 | 568 | builtin.Arch.thumb, |
| 535 | 569 | builtin.Arch.armv8_3a, |
| 536 | 570 | builtin.Arch.armv8_2a, |
src/os.cpp+2-2| ... | ... | @@ -90,7 +90,7 @@ static void populate_termination(Termination *term, int status) { |
| 90 | 90 | static void os_spawn_process_posix(const char *exe, ZigList<const char *> &args, Termination *term) { |
| 91 | 91 | pid_t pid = fork(); |
| 92 | 92 | if (pid == -1) |
| 93 | zig_panic("fork failed"); | |
| 93 | zig_panic("fork failed: %s", strerror(errno)); | |
| 94 | 94 | if (pid == 0) { |
| 95 | 95 | // child |
| 96 | 96 | const char **argv = allocate<const char *>(args.length + 2); |
| ... | ... | @@ -806,7 +806,7 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args, |
| 806 | 806 | |
| 807 | 807 | pid_t pid = fork(); |
| 808 | 808 | if (pid == -1) |
| 809 | zig_panic("fork failed"); | |
| 809 | zig_panic("fork failed: %s", strerror(errno)); | |
| 810 | 810 | if (pid == 0) { |
| 811 | 811 | // child |
| 812 | 812 | if (dup2(stdin_pipe[0], STDIN_FILENO) == -1) |
src/target.cpp+18-3| ... | ... | @@ -55,8 +55,22 @@ static const ArchType arch_list[] = { |
| 55 | 55 | {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v5te}, |
| 56 | 56 | {ZigLLVM_armeb, ZigLLVM_ARMSubArch_v4t}, |
| 57 | 57 | |
| 58 | {ZigLLVM_aarch64, ZigLLVM_NoSubArch}, | |
| 59 | {ZigLLVM_aarch64_be, ZigLLVM_NoSubArch}, | |
| 58 | {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_3a}, | |
| 59 | {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_2a}, | |
| 60 | {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8_1a}, | |
| 61 | {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8}, | |
| 62 | {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8r}, | |
| 63 | {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8m_baseline}, | |
| 64 | {ZigLLVM_aarch64, ZigLLVM_ARMSubArch_v8m_mainline}, | |
| 65 | ||
| 66 | {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_3a}, | |
| 67 | {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_2a}, | |
| 68 | {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8_1a}, | |
| 69 | {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8}, | |
| 70 | {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8r}, | |
| 71 | {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8m_baseline}, | |
| 72 | {ZigLLVM_aarch64_be, ZigLLVM_ARMSubArch_v8m_mainline}, | |
| 73 | ||
| 60 | 74 | {ZigLLVM_arc, ZigLLVM_NoSubArch}, |
| 61 | 75 | {ZigLLVM_avr, ZigLLVM_NoSubArch}, |
| 62 | 76 | {ZigLLVM_bpfel, ZigLLVM_NoSubArch}, |
| ... | ... | @@ -943,8 +957,9 @@ const char *arch_stack_pointer_register_name(const ArchType *arch) { |
| 943 | 957 | return "sp"; |
| 944 | 958 | case ZigLLVM_x86_64: |
| 945 | 959 | return "rsp"; |
| 946 | ||
| 947 | 960 | case ZigLLVM_aarch64: |
| 961 | return "sp"; | |
| 962 | ||
| 948 | 963 | case ZigLLVM_arm: |
| 949 | 964 | case ZigLLVM_thumb: |
| 950 | 965 | case ZigLLVM_aarch64_be: |
std/elf.zig+5| ... | ... | @@ -859,6 +859,11 @@ pub const Elf_MIPS_ABIFlags_v0 = extern struct { |
| 859 | 859 | flags2: Elf32_Word, |
| 860 | 860 | }; |
| 861 | 861 | |
| 862 | pub const Auxv = switch (@sizeOf(usize)) { | |
| 863 | 4 => Elf32_auxv_t, | |
| 864 | 8 => Elf64_auxv_t, | |
| 865 | else => @compileError("expected pointer size of 32 or 64"), | |
| 866 | }; | |
| 862 | 867 | pub const Ehdr = switch (@sizeOf(usize)) { |
| 863 | 868 | 4 => Elf32_Ehdr, |
| 864 | 869 | 8 => Elf64_Ehdr, |
std/fmt/index.zig+3-1| ... | ... | @@ -1044,7 +1044,9 @@ test "fmt.format" { |
| 1044 | 1044 | const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64); |
| 1045 | 1045 | assert(mem.eql(u8, result, "f64: nan\n")); |
| 1046 | 1046 | } |
| 1047 | { | |
| 1047 | if (builtin.arch != builtin.Arch.armv8) { | |
| 1048 | // negative nan is not defined by IEE 754, | |
| 1049 | // and ARM thus normalizes it to positive nan | |
| 1048 | 1050 | var buf1: [32]u8 = undefined; |
| 1049 | 1051 | const result = try bufPrint(buf1[0..], "f64: {}\n", -math.nan_f64); |
| 1050 | 1052 | assert(mem.eql(u8, result, "f64: -nan\n")); |
std/math/index.zig+7-1| ... | ... | @@ -8,7 +8,7 @@ pub const pi = 3.14159265358979323846264338327950288419716939937510; |
| 8 | 8 | |
| 9 | 9 | // float.h details |
| 10 | 10 | pub const f64_true_min = 4.94065645841246544177e-324; |
| 11 | pub const f64_min = 2.22507385850720138309e-308; | |
| 11 | pub const f64_min = 2.2250738585072014e-308; | |
| 12 | 12 | pub const f64_max = 1.79769313486231570815e+308; |
| 13 | 13 | pub const f64_epsilon = 2.22044604925031308085e-16; |
| 14 | 14 | pub const f64_toint = 1.0 / f64_epsilon; |
| ... | ... | @@ -650,3 +650,9 @@ pub fn lossyCast(comptime T: type, value: var) T { |
| 650 | 650 | else => @compileError("bad type"), |
| 651 | 651 | } |
| 652 | 652 | } |
| 653 | ||
| 654 | test "math.f64_min" { | |
| 655 | const f64_min_u64 = 0x0010000000000000; | |
| 656 | const fmin: f64 = f64_min; | |
| 657 | assert(@bitCast(u64, fmin) == f64_min_u64); | |
| 658 | } |
std/os/index.zig+11-7| ... | ... | @@ -655,16 +655,21 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError { |
| 655 | 655 | } |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | pub var linux_aux_raw = []usize{0} ** 38; | |
| 658 | pub var linux_elf_aux_maybe: ?[*]std.elf.Auxv = null; | |
| 659 | 659 | pub var posix_environ_raw: [][*]u8 = undefined; |
| 660 | 660 | |
| 661 | 661 | /// See std.elf for the constants. |
| 662 | 662 | pub fn linuxGetAuxVal(index: usize) usize { |
| 663 | 663 | if (builtin.link_libc) { |
| 664 | 664 | return usize(std.c.getauxval(index)); |
| 665 | } else { | |
| 666 | return linux_aux_raw[index]; | |
| 665 | } else if (linux_elf_aux_maybe) |auxv| { | |
| 666 | var i: usize = 0; | |
| 667 | while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) { | |
| 668 | if (auxv[i].a_type == index) | |
| 669 | return auxv[i].a_un.a_val; | |
| 670 | } | |
| 667 | 671 | } |
| 672 | return 0; | |
| 668 | 673 | } |
| 669 | 674 | |
| 670 | 675 | pub fn getBaseAddress() usize { |
| ... | ... | @@ -1676,7 +1681,7 @@ pub const Dir = struct { |
| 1676 | 1681 | } |
| 1677 | 1682 | |
| 1678 | 1683 | while (true) { |
| 1679 | const result = posix.getdents(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len); | |
| 1684 | const result = posix.getdents64(self.handle.fd, self.handle.buf.ptr, self.handle.buf.len); | |
| 1680 | 1685 | const err = posix.getErrno(result); |
| 1681 | 1686 | if (err > 0) { |
| 1682 | 1687 | switch (err) { |
| ... | ... | @@ -1694,7 +1699,7 @@ pub const Dir = struct { |
| 1694 | 1699 | break; |
| 1695 | 1700 | } |
| 1696 | 1701 | } |
| 1697 | const linux_entry = @ptrCast(*align(1) posix.dirent, &self.handle.buf[self.handle.index]); | |
| 1702 | const linux_entry = @ptrCast(*align(1) posix.dirent64, &self.handle.buf[self.handle.index]); | |
| 1698 | 1703 | const next_index = self.handle.index + linux_entry.d_reclen; |
| 1699 | 1704 | self.handle.index = next_index; |
| 1700 | 1705 | |
| ... | ... | @@ -1705,8 +1710,7 @@ pub const Dir = struct { |
| 1705 | 1710 | continue :start_over; |
| 1706 | 1711 | } |
| 1707 | 1712 | |
| 1708 | const type_char = self.handle.buf[next_index - 1]; | |
| 1709 | const entry_kind = switch (type_char) { | |
| 1713 | const entry_kind = switch (linux_entry.d_type) { | |
| 1710 | 1714 | posix.DT_BLK => Entry.Kind.BlockDevice, |
| 1711 | 1715 | posix.DT_CHR => Entry.Kind.CharacterDevice, |
| 1712 | 1716 | posix.DT_DIR => Entry.Kind.Directory, |
std/os/linux/arm64.zig created+465| ... | ... | @@ -0,0 +1,465 @@ |
| 1 | const std = @import("../../index.zig"); | |
| 2 | const linux = std.os.linux; | |
| 3 | const socklen_t = linux.socklen_t; | |
| 4 | const iovec = linux.iovec; | |
| 5 | ||
| 6 | pub const SYS_io_setup = 0; | |
| 7 | pub const SYS_io_destroy = 1; | |
| 8 | pub const SYS_io_submit = 2; | |
| 9 | pub const SYS_io_cancel = 3; | |
| 10 | pub const SYS_io_getevents = 4; | |
| 11 | pub const SYS_setxattr = 5; | |
| 12 | pub const SYS_lsetxattr = 6; | |
| 13 | pub const SYS_fsetxattr = 7; | |
| 14 | pub const SYS_getxattr = 8; | |
| 15 | pub const SYS_lgetxattr = 9; | |
| 16 | pub const SYS_fgetxattr = 10; | |
| 17 | pub const SYS_listxattr = 11; | |
| 18 | pub const SYS_llistxattr = 12; | |
| 19 | pub const SYS_flistxattr = 13; | |
| 20 | pub const SYS_removexattr = 14; | |
| 21 | pub const SYS_lremovexattr = 15; | |
| 22 | pub const SYS_fremovexattr = 16; | |
| 23 | pub const SYS_getcwd = 17; | |
| 24 | pub const SYS_lookup_dcookie = 18; | |
| 25 | pub const SYS_eventfd2 = 19; | |
| 26 | pub const SYS_epoll_create1 = 20; | |
| 27 | pub const SYS_epoll_ctl = 21; | |
| 28 | pub const SYS_epoll_pwait = 22; | |
| 29 | pub const SYS_dup = 23; | |
| 30 | pub const SYS_dup3 = 24; | |
| 31 | pub const SYS_fcntl = 25; | |
| 32 | pub const SYS_inotify_init1 = 26; | |
| 33 | pub const SYS_inotify_add_watch = 27; | |
| 34 | pub const SYS_inotify_rm_watch = 28; | |
| 35 | pub const SYS_ioctl = 29; | |
| 36 | pub const SYS_ioprio_set = 30; | |
| 37 | pub const SYS_ioprio_get = 31; | |
| 38 | pub const SYS_flock = 32; | |
| 39 | pub const SYS_mknodat = 33; | |
| 40 | pub const SYS_mkdirat = 34; | |
| 41 | pub const SYS_unlinkat = 35; | |
| 42 | pub const SYS_symlinkat = 36; | |
| 43 | pub const SYS_linkat = 37; | |
| 44 | pub const SYS_renameat = 38; | |
| 45 | pub const SYS_umount2 = 39; | |
| 46 | pub const SYS_mount = 40; | |
| 47 | pub const SYS_pivot_root = 41; | |
| 48 | pub const SYS_nfsservctl = 42; | |
| 49 | pub const SYS_statfs = 43; | |
| 50 | pub const SYS_fstatfs = 44; | |
| 51 | pub const SYS_truncate = 45; | |
| 52 | pub const SYS_ftruncate = 46; | |
| 53 | pub const SYS_fallocate = 47; | |
| 54 | pub const SYS_faccessat = 48; | |
| 55 | pub const SYS_chdir = 49; | |
| 56 | pub const SYS_fchdir = 50; | |
| 57 | pub const SYS_chroot = 51; | |
| 58 | pub const SYS_fchmod = 52; | |
| 59 | pub const SYS_fchmodat = 53; | |
| 60 | pub const SYS_fchownat = 54; | |
| 61 | pub const SYS_fchown = 55; | |
| 62 | pub const SYS_openat = 56; | |
| 63 | pub const SYS_close = 57; | |
| 64 | pub const SYS_vhangup = 58; | |
| 65 | pub const SYS_pipe2 = 59; | |
| 66 | pub const SYS_quotactl = 60; | |
| 67 | pub const SYS_getdents64 = 61; | |
| 68 | pub const SYS_lseek = 62; | |
| 69 | pub const SYS_read = 63; | |
| 70 | pub const SYS_write = 64; | |
| 71 | pub const SYS_readv = 65; | |
| 72 | pub const SYS_writev = 66; | |
| 73 | pub const SYS_pread64 = 67; | |
| 74 | pub const SYS_pwrite64 = 68; | |
| 75 | pub const SYS_preadv = 69; | |
| 76 | pub const SYS_pwritev = 70; | |
| 77 | pub const SYS_pselect6 = 72; | |
| 78 | pub const SYS_ppoll = 73; | |
| 79 | pub const SYS_signalfd4 = 74; | |
| 80 | pub const SYS_vmsplice = 75; | |
| 81 | pub const SYS_splice = 76; | |
| 82 | pub const SYS_tee = 77; | |
| 83 | pub const SYS_readlinkat = 78; | |
| 84 | pub const SYS_fstatat = 79; | |
| 85 | pub const SYS_fstat = 80; | |
| 86 | pub const SYS_sync = 81; | |
| 87 | pub const SYS_fsync = 82; | |
| 88 | pub const SYS_fdatasync = 83; | |
| 89 | pub const SYS_sync_file_range2 = 84; | |
| 90 | pub const SYS_sync_file_range = 84; | |
| 91 | pub const SYS_timerfd_create = 85; | |
| 92 | pub const SYS_timerfd_settime = 86; | |
| 93 | pub const SYS_timerfd_gettime = 87; | |
| 94 | pub const SYS_utimensat = 88; | |
| 95 | pub const SYS_acct = 89; | |
| 96 | pub const SYS_capget = 90; | |
| 97 | pub const SYS_capset = 91; | |
| 98 | pub const SYS_personality = 92; | |
| 99 | pub const SYS_exit = 93; | |
| 100 | pub const SYS_exit_group = 94; | |
| 101 | pub const SYS_waitid = 95; | |
| 102 | pub const SYS_set_tid_address = 96; | |
| 103 | pub const SYS_unshare = 97; | |
| 104 | pub const SYS_futex = 98; | |
| 105 | pub const SYS_set_robust_list = 99; | |
| 106 | pub const SYS_get_robust_list = 100; | |
| 107 | pub const SYS_nanosleep = 101; | |
| 108 | pub const SYS_getitimer = 102; | |
| 109 | pub const SYS_setitimer = 103; | |
| 110 | pub const SYS_kexec_load = 104; | |
| 111 | pub const SYS_init_module = 105; | |
| 112 | pub const SYS_delete_module = 106; | |
| 113 | pub const SYS_timer_create = 107; | |
| 114 | pub const SYS_timer_gettime = 108; | |
| 115 | pub const SYS_timer_getoverrun = 109; | |
| 116 | pub const SYS_timer_settime = 110; | |
| 117 | pub const SYS_timer_delete = 111; | |
| 118 | pub const SYS_clock_settime = 112; | |
| 119 | pub const SYS_clock_gettime = 113; | |
| 120 | pub const SYS_clock_getres = 114; | |
| 121 | pub const SYS_clock_nanosleep = 115; | |
| 122 | pub const SYS_syslog = 116; | |
| 123 | pub const SYS_ptrace = 117; | |
| 124 | pub const SYS_sched_setparam = 118; | |
| 125 | pub const SYS_sched_setscheduler = 119; | |
| 126 | pub const SYS_sched_getscheduler = 120; | |
| 127 | pub const SYS_sched_getparam = 121; | |
| 128 | pub const SYS_sched_setaffinity = 122; | |
| 129 | pub const SYS_sched_getaffinity = 123; | |
| 130 | pub const SYS_sched_yield = 124; | |
| 131 | pub const SYS_sched_get_priority_max = 125; | |
| 132 | pub const SYS_sched_get_priority_min = 126; | |
| 133 | pub const SYS_sched_rr_get_interval = 127; | |
| 134 | pub const SYS_restart_syscall = 128; | |
| 135 | pub const SYS_kill = 129; | |
| 136 | pub const SYS_tkill = 130; | |
| 137 | pub const SYS_tgkill = 131; | |
| 138 | pub const SYS_sigaltstack = 132; | |
| 139 | pub const SYS_rt_sigsuspend = 133; | |
| 140 | pub const SYS_rt_sigaction = 134; | |
| 141 | pub const SYS_rt_sigprocmask = 135; | |
| 142 | pub const SYS_rt_sigpending = 136; | |
| 143 | pub const SYS_rt_sigtimedwait = 137; | |
| 144 | pub const SYS_rt_sigqueueinfo = 138; | |
| 145 | pub const SYS_rt_sigreturn = 139; | |
| 146 | pub const SYS_setpriority = 140; | |
| 147 | pub const SYS_getpriority = 141; | |
| 148 | pub const SYS_reboot = 142; | |
| 149 | pub const SYS_setregid = 143; | |
| 150 | pub const SYS_setgid = 144; | |
| 151 | pub const SYS_setreuid = 145; | |
| 152 | pub const SYS_setuid = 146; | |
| 153 | pub const SYS_setresuid = 147; | |
| 154 | pub const SYS_getresuid = 148; | |
| 155 | pub const SYS_setresgid = 149; | |
| 156 | pub const SYS_getresgid = 150; | |
| 157 | pub const SYS_setfsuid = 151; | |
| 158 | pub const SYS_setfsgid = 152; | |
| 159 | pub const SYS_times = 153; | |
| 160 | pub const SYS_setpgid = 154; | |
| 161 | pub const SYS_getpgid = 155; | |
| 162 | pub const SYS_getsid = 156; | |
| 163 | pub const SYS_setsid = 157; | |
| 164 | pub const SYS_getgroups = 158; | |
| 165 | pub const SYS_setgroups = 159; | |
| 166 | pub const SYS_uname = 160; | |
| 167 | pub const SYS_sethostname = 161; | |
| 168 | pub const SYS_setdomainname = 162; | |
| 169 | pub const SYS_getrlimit = 163; | |
| 170 | pub const SYS_setrlimit = 164; | |
| 171 | pub const SYS_getrusage = 165; | |
| 172 | pub const SYS_umask = 166; | |
| 173 | pub const SYS_prctl = 167; | |
| 174 | pub const SYS_getcpu = 168; | |
| 175 | pub const SYS_gettimeofday = 169; | |
| 176 | pub const SYS_settimeofday = 170; | |
| 177 | pub const SYS_adjtimex = 171; | |
| 178 | pub const SYS_getpid = 172; | |
| 179 | pub const SYS_getppid = 173; | |
| 180 | pub const SYS_getuid = 174; | |
| 181 | pub const SYS_geteuid = 175; | |
| 182 | pub const SYS_getgid = 176; | |
| 183 | pub const SYS_getegid = 177; | |
| 184 | pub const SYS_gettid = 178; | |
| 185 | pub const SYS_sysinfo = 179; | |
| 186 | pub const SYS_mq_open = 180; | |
| 187 | pub const SYS_mq_unlink = 181; | |
| 188 | pub const SYS_mq_timedsend = 182; | |
| 189 | pub const SYS_mq_timedreceive = 183; | |
| 190 | pub const SYS_mq_notify = 184; | |
| 191 | pub const SYS_mq_getsetattr = 185; | |
| 192 | pub const SYS_msgget = 186; | |
| 193 | pub const SYS_msgctl = 187; | |
| 194 | pub const SYS_msgrcv = 188; | |
| 195 | pub const SYS_msgsnd = 189; | |
| 196 | pub const SYS_semget = 190; | |
| 197 | pub const SYS_semctl = 191; | |
| 198 | pub const SYS_semtimedop = 192; | |
| 199 | pub const SYS_semop = 193; | |
| 200 | pub const SYS_shmget = 194; | |
| 201 | pub const SYS_shmctl = 195; | |
| 202 | pub const SYS_shmat = 196; | |
| 203 | pub const SYS_shmdt = 197; | |
| 204 | pub const SYS_socket = 198; | |
| 205 | pub const SYS_socketpair = 199; | |
| 206 | pub const SYS_bind = 200; | |
| 207 | pub const SYS_listen = 201; | |
| 208 | pub const SYS_accept = 202; | |
| 209 | pub const SYS_connect = 203; | |
| 210 | pub const SYS_getsockname = 204; | |
| 211 | pub const SYS_getpeername = 205; | |
| 212 | pub const SYS_sendto = 206; | |
| 213 | pub const SYS_recvfrom = 207; | |
| 214 | pub const SYS_setsockopt = 208; | |
| 215 | pub const SYS_getsockopt = 209; | |
| 216 | pub const SYS_shutdown = 210; | |
| 217 | pub const SYS_sendmsg = 211; | |
| 218 | pub const SYS_recvmsg = 212; | |
| 219 | pub const SYS_readahead = 213; | |
| 220 | pub const SYS_brk = 214; | |
| 221 | pub const SYS_munmap = 215; | |
| 222 | pub const SYS_mremap = 216; | |
| 223 | pub const SYS_add_key = 217; | |
| 224 | pub const SYS_request_key = 218; | |
| 225 | pub const SYS_keyctl = 219; | |
| 226 | pub const SYS_clone = 220; | |
| 227 | pub const SYS_execve = 221; | |
| 228 | pub const SYS_mmap = 222; | |
| 229 | pub const SYS_fadvise64 = 223; | |
| 230 | pub const SYS_swapon = 224; | |
| 231 | pub const SYS_swapoff = 225; | |
| 232 | pub const SYS_mprotect = 226; | |
| 233 | pub const SYS_msync = 227; | |
| 234 | pub const SYS_mlock = 228; | |
| 235 | pub const SYS_munlock = 229; | |
| 236 | pub const SYS_mlockall = 230; | |
| 237 | pub const SYS_munlockall = 231; | |
| 238 | pub const SYS_mincore = 232; | |
| 239 | pub const SYS_madvise = 233; | |
| 240 | pub const SYS_remap_file_pages = 234; | |
| 241 | pub const SYS_mbind = 235; | |
| 242 | pub const SYS_get_mempolicy = 236; | |
| 243 | pub const SYS_set_mempolicy = 237; | |
| 244 | pub const SYS_migrate_pages = 238; | |
| 245 | pub const SYS_move_pages = 239; | |
| 246 | pub const SYS_rt_tgsigqueueinfo = 240; | |
| 247 | pub const SYS_perf_event_open = 241; | |
| 248 | pub const SYS_accept4 = 242; | |
| 249 | pub const SYS_recvmmsg = 243; | |
| 250 | pub const SYS_arch_specific_syscall = 244; | |
| 251 | pub const SYS_wait4 = 260; | |
| 252 | pub const SYS_prlimit64 = 261; | |
| 253 | pub const SYS_fanotify_init = 262; | |
| 254 | pub const SYS_fanotify_mark = 263; | |
| 255 | pub const SYS_clock_adjtime = 266; | |
| 256 | pub const SYS_syncfs = 267; | |
| 257 | pub const SYS_setns = 268; | |
| 258 | pub const SYS_sendmmsg = 269; | |
| 259 | pub const SYS_process_vm_readv = 270; | |
| 260 | pub const SYS_process_vm_writev = 271; | |
| 261 | pub const SYS_kcmp = 272; | |
| 262 | pub const SYS_finit_module = 273; | |
| 263 | pub const SYS_sched_setattr = 274; | |
| 264 | pub const SYS_sched_getattr = 275; | |
| 265 | pub const SYS_renameat2 = 276; | |
| 266 | pub const SYS_seccomp = 277; | |
| 267 | pub const SYS_getrandom = 278; | |
| 268 | pub const SYS_memfd_create = 279; | |
| 269 | pub const SYS_bpf = 280; | |
| 270 | pub const SYS_execveat = 281; | |
| 271 | pub const SYS_userfaultfd = 282; | |
| 272 | pub const SYS_membarrier = 283; | |
| 273 | pub const SYS_mlock2 = 284; | |
| 274 | pub const SYS_copy_file_range = 285; | |
| 275 | pub const SYS_preadv2 = 286; | |
| 276 | pub const SYS_pwritev2 = 287; | |
| 277 | pub const SYS_pkey_mprotect = 288; | |
| 278 | pub const SYS_pkey_alloc = 289; | |
| 279 | pub const SYS_pkey_free = 290; | |
| 280 | pub const SYS_statx = 291; | |
| 281 | pub const SYS_io_pgetevents = 292; | |
| 282 | pub const SYS_syscalls = 293; | |
| 283 | ||
| 284 | pub const O_CREAT = 0o100; | |
| 285 | pub const O_EXCL = 0o200; | |
| 286 | pub const O_NOCTTY = 0o400; | |
| 287 | pub const O_TRUNC = 0o1000; | |
| 288 | pub const O_APPEND = 0o2000; | |
| 289 | pub const O_NONBLOCK = 0o4000; | |
| 290 | pub const O_DSYNC = 0o10000; | |
| 291 | pub const O_SYNC = 0o4010000; | |
| 292 | pub const O_RSYNC = 0o4010000; | |
| 293 | pub const O_DIRECTORY = 0o200000; | |
| 294 | pub const O_NOFOLLOW = 0o400000; | |
| 295 | pub const O_CLOEXEC = 0o2000000; | |
| 296 | ||
| 297 | pub const O_ASYNC = 0o20000; | |
| 298 | pub const O_DIRECT = 0o40000; | |
| 299 | pub const O_LARGEFILE = 0; | |
| 300 | pub const O_NOATIME = 0o1000000; | |
| 301 | pub const O_PATH = 0o10000000; | |
| 302 | pub const O_TMPFILE = 0o20200000; | |
| 303 | pub const O_NDELAY = O_NONBLOCK; | |
| 304 | ||
| 305 | pub const F_DUPFD = 0; | |
| 306 | pub const F_GETFD = 1; | |
| 307 | pub const F_SETFD = 2; | |
| 308 | pub const F_GETFL = 3; | |
| 309 | pub const F_SETFL = 4; | |
| 310 | ||
| 311 | pub const F_SETOWN = 8; | |
| 312 | pub const F_GETOWN = 9; | |
| 313 | pub const F_SETSIG = 10; | |
| 314 | pub const F_GETSIG = 11; | |
| 315 | ||
| 316 | pub const F_GETLK = 5; | |
| 317 | pub const F_SETLK = 6; | |
| 318 | pub const F_SETLKW = 7; | |
| 319 | ||
| 320 | pub const F_SETOWN_EX = 15; | |
| 321 | pub const F_GETOWN_EX = 16; | |
| 322 | ||
| 323 | pub const F_GETOWNER_UIDS = 17; | |
| 324 | ||
| 325 | pub const AT_FDCWD = -100; | |
| 326 | pub const AT_SYMLINK_NOFOLLOW = 0x100; | |
| 327 | pub const AT_REMOVEDIR = 0x200; | |
| 328 | pub const AT_SYMLINK_FOLLOW = 0x400; | |
| 329 | pub const AT_NO_AUTOMOUNT = 0x800; | |
| 330 | pub const AT_EMPTY_PATH = 0x1000; | |
| 331 | ||
| 332 | pub const VDSO_USEFUL = true; | |
| 333 | pub const VDSO_CGT_SYM = "__kernel_clock_gettime"; | |
| 334 | pub const VDSO_CGT_VER = "LINUX_2.6.39"; | |
| 335 | ||
| 336 | pub fn syscall0(number: usize) usize { | |
| 337 | return asm volatile ("svc #0" | |
| 338 | : [ret] "={x0}" (-> usize) | |
| 339 | : [number] "{x8}" (number) | |
| 340 | ); | |
| 341 | } | |
| 342 | ||
| 343 | pub fn syscall1(number: usize, arg1: usize) usize { | |
| 344 | return asm volatile ("svc #0" | |
| 345 | : [ret] "={x0}" (-> usize) | |
| 346 | : [number] "{x8}" (number), | |
| 347 | [arg1] "{x0}" (arg1) | |
| 348 | ); | |
| 349 | } | |
| 350 | ||
| 351 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | |
| 352 | return asm volatile ("svc #0" | |
| 353 | : [ret] "={x0}" (-> usize) | |
| 354 | : [number] "{x8}" (number), | |
| 355 | [arg1] "{x0}" (arg1), | |
| 356 | [arg2] "{x1}" (arg2) | |
| 357 | ); | |
| 358 | } | |
| 359 | ||
| 360 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 361 | return asm volatile ("svc #0" | |
| 362 | : [ret] "={x0}" (-> usize) | |
| 363 | : [number] "{x8}" (number), | |
| 364 | [arg1] "{x0}" (arg1), | |
| 365 | [arg2] "{x1}" (arg2), | |
| 366 | [arg3] "{x2}" (arg3) | |
| 367 | ); | |
| 368 | } | |
| 369 | ||
| 370 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 371 | return asm volatile ("svc #0" | |
| 372 | : [ret] "={x0}" (-> usize) | |
| 373 | : [number] "{x8}" (number), | |
| 374 | [arg1] "{x0}" (arg1), | |
| 375 | [arg2] "{x1}" (arg2), | |
| 376 | [arg3] "{x2}" (arg3), | |
| 377 | [arg4] "{x3}" (arg4) | |
| 378 | ); | |
| 379 | } | |
| 380 | ||
| 381 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 382 | return asm volatile ("svc #0" | |
| 383 | : [ret] "={x0}" (-> usize) | |
| 384 | : [number] "{x8}" (number), | |
| 385 | [arg1] "{x0}" (arg1), | |
| 386 | [arg2] "{x1}" (arg2), | |
| 387 | [arg3] "{x2}" (arg3), | |
| 388 | [arg4] "{x3}" (arg4), | |
| 389 | [arg5] "{x4}" (arg5) | |
| 390 | ); | |
| 391 | } | |
| 392 | ||
| 393 | pub fn syscall6( | |
| 394 | number: usize, | |
| 395 | arg1: usize, | |
| 396 | arg2: usize, | |
| 397 | arg3: usize, | |
| 398 | arg4: usize, | |
| 399 | arg5: usize, | |
| 400 | arg6: usize, | |
| 401 | ) usize { | |
| 402 | return asm volatile ("svc #0" | |
| 403 | : [ret] "={x0}" (-> usize) | |
| 404 | : [number] "{x8}" (number), | |
| 405 | [arg1] "{x0}" (arg1), | |
| 406 | [arg2] "{x1}" (arg2), | |
| 407 | [arg3] "{x2}" (arg3), | |
| 408 | [arg4] "{x3}" (arg4), | |
| 409 | [arg5] "{x4}" (arg5), | |
| 410 | [arg6] "{x5}" (arg6) | |
| 411 | ); | |
| 412 | } | |
| 413 | ||
| 414 | /// This matches the libc clone function. | |
| 415 | pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; | |
| 416 | ||
| 417 | pub const msghdr = extern struct { | |
| 418 | msg_name: *u8, | |
| 419 | msg_namelen: socklen_t, | |
| 420 | msg_iov: *iovec, | |
| 421 | msg_iovlen: i32, | |
| 422 | __pad1: i32, | |
| 423 | msg_control: *u8, | |
| 424 | msg_controllen: socklen_t, | |
| 425 | __pad2: socklen_t, | |
| 426 | msg_flags: i32, | |
| 427 | }; | |
| 428 | ||
| 429 | /// Renamed to Stat to not conflict with the stat function. | |
| 430 | pub const Stat = extern struct { | |
| 431 | dev: u64, | |
| 432 | ino: u64, | |
| 433 | nlink: usize, | |
| 434 | ||
| 435 | mode: u32, | |
| 436 | uid: u32, | |
| 437 | gid: u32, | |
| 438 | __pad0: u32, | |
| 439 | rdev: u64, | |
| 440 | size: i64, | |
| 441 | blksize: isize, | |
| 442 | blocks: i64, | |
| 443 | ||
| 444 | atim: timespec, | |
| 445 | mtim: timespec, | |
| 446 | ctim: timespec, | |
| 447 | __unused: [3]isize, | |
| 448 | }; | |
| 449 | ||
| 450 | pub const timespec = extern struct { | |
| 451 | tv_sec: isize, | |
| 452 | tv_nsec: isize, | |
| 453 | }; | |
| 454 | ||
| 455 | pub const timeval = extern struct { | |
| 456 | tv_sec: isize, | |
| 457 | tv_usec: isize, | |
| 458 | }; | |
| 459 | ||
| 460 | pub const timezone = extern struct { | |
| 461 | tz_minuteswest: i32, | |
| 462 | tz_dsttime: i32, | |
| 463 | }; | |
| 464 | ||
| 465 | pub const Elf_Symndx = u32; |
std/os/linux/index.zig+82-23| ... | ... | @@ -5,6 +5,7 @@ const vdso = @import("vdso.zig"); |
| 5 | 5 | pub use switch (builtin.arch) { |
| 6 | 6 | builtin.Arch.x86_64 => @import("x86_64.zig"), |
| 7 | 7 | builtin.Arch.i386 => @import("i386.zig"), |
| 8 | builtin.Arch.aarch64v8 => @import("arm64.zig"), | |
| 8 | 9 | else => @compileError("unsupported arch"), |
| 9 | 10 | }; |
| 10 | 11 | pub use @import("errno.zig"); |
| ... | ... | @@ -697,7 +698,11 @@ pub fn getErrno(r: usize) usize { |
| 697 | 698 | } |
| 698 | 699 | |
| 699 | 700 | pub fn dup2(old: i32, new: i32) usize { |
| 700 | return syscall2(SYS_dup2, @intCast(usize, old), @intCast(usize, new)); | |
| 701 | return dup3(old, new, 0); | |
| 702 | } | |
| 703 | ||
| 704 | pub fn dup3(old: i32, new: i32, flags: u32) usize { | |
| 705 | return syscall3(SYS_dup3, @intCast(usize, old), @intCast(usize, new), flags); | |
| 701 | 706 | } |
| 702 | 707 | |
| 703 | 708 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -716,7 +721,7 @@ pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[* |
| 716 | 721 | } |
| 717 | 722 | |
| 718 | 723 | pub fn fork() usize { |
| 719 | return syscall0(SYS_fork); | |
| 724 | return clone2(SIGCHLD, 0); | |
| 720 | 725 | } |
| 721 | 726 | |
| 722 | 727 | /// This must be inline, and inline call the syscall function, because if the |
| ... | ... | @@ -740,8 +745,8 @@ pub fn getcwd(buf: [*]u8, size: usize) usize { |
| 740 | 745 | return syscall2(SYS_getcwd, @ptrToInt(buf), size); |
| 741 | 746 | } |
| 742 | 747 | |
| 743 | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { | |
| 744 | return syscall3(SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); | |
| 748 | pub fn getdents64(fd: i32, dirp: [*]u8, count: usize) usize { | |
| 749 | return syscall3(SYS_getdents64, @intCast(usize, fd), @ptrToInt(dirp), count); | |
| 745 | 750 | } |
| 746 | 751 | |
| 747 | 752 | pub fn inotify_init1(flags: u32) usize { |
| ... | ... | @@ -763,16 +768,26 @@ pub fn isatty(fd: i32) bool { |
| 763 | 768 | |
| 764 | 769 | // TODO https://github.com/ziglang/zig/issues/265 |
| 765 | 770 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 766 | return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 771 | return readlinkat(AT_FDCWD, path, buf_ptr, buf_len); | |
| 772 | } | |
| 773 | ||
| 774 | // TODO https://github.com/ziglang/zig/issues/265 | |
| 775 | pub fn readlinkat(dirfd: i32, noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | |
| 776 | return syscall4(SYS_readlinkat, @intCast(usize, dirfd), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 767 | 777 | } |
| 768 | 778 | |
| 769 | 779 | // TODO https://github.com/ziglang/zig/issues/265 |
| 770 | 780 | pub fn mkdir(path: [*]const u8, mode: u32) usize { |
| 771 | return syscall2(SYS_mkdir, @ptrToInt(path), mode); | |
| 781 | return mkdirat(AT_FDCWD, path, mode); | |
| 782 | } | |
| 783 | ||
| 784 | // TODO https://github.com/ziglang/zig/issues/265 | |
| 785 | pub fn mkdirat(dirfd: i32, path: [*]const u8, mode: u32) usize { | |
| 786 | return syscall3(SYS_mkdirat, @intCast(usize, dirfd), @ptrToInt(path), mode); | |
| 772 | 787 | } |
| 773 | 788 | |
| 774 | 789 | // TODO https://github.com/ziglang/zig/issues/265 |
| 775 | pub fn mount(special: [*]const u8, dir: [*]const u8, fstype: [*]const u8, flags: usize, data: usize) usize { | |
| 790 | pub fn mount(special: [*]const u8, dir: [*]const u8, fstype: [*]const u8, flags: u32, data: usize) usize { | |
| 776 | 791 | return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data); |
| 777 | 792 | } |
| 778 | 793 | |
| ... | ... | @@ -816,28 +831,38 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us |
| 816 | 831 | |
| 817 | 832 | // TODO https://github.com/ziglang/zig/issues/265 |
| 818 | 833 | pub fn rmdir(path: [*]const u8) usize { |
| 819 | return syscall1(SYS_rmdir, @ptrToInt(path)); | |
| 834 | return unlinkat(AT_FDCWD, path, AT_REMOVEDIR); | |
| 820 | 835 | } |
| 821 | 836 | |
| 822 | 837 | // TODO https://github.com/ziglang/zig/issues/265 |
| 823 | 838 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { |
| 824 | return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); | |
| 839 | return symlinkat(existing, AT_FDCWD, new); | |
| 840 | } | |
| 841 | ||
| 842 | // TODO https://github.com/ziglang/zig/issues/265 | |
| 843 | pub fn symlinkat(existing: [*]const u8, newfd: i32, newpath: [*]const u8) usize { | |
| 844 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @intCast(usize, newfd), @ptrToInt(newpath)); | |
| 825 | 845 | } |
| 826 | 846 | |
| 847 | // TODO https://github.com/ziglang/zig/issues/265 | |
| 827 | 848 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { |
| 828 | 849 | return syscall4(SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset); |
| 829 | 850 | } |
| 830 | 851 | |
| 831 | 852 | // TODO https://github.com/ziglang/zig/issues/265 |
| 832 | 853 | pub fn access(path: [*]const u8, mode: u32) usize { |
| 833 | return syscall2(SYS_access, @ptrToInt(path), mode); | |
| 854 | return faccessat(AT_FDCWD, path, mode); | |
| 855 | } | |
| 856 | ||
| 857 | pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32) usize { | |
| 858 | return syscall3(SYS_faccessat, @intCast(usize, dirfd), @ptrToInt(path), mode); | |
| 834 | 859 | } |
| 835 | 860 | |
| 836 | 861 | pub fn pipe(fd: *[2]i32) usize { |
| 837 | 862 | return pipe2(fd, 0); |
| 838 | 863 | } |
| 839 | 864 | |
| 840 | pub fn pipe2(fd: *[2]i32, flags: usize) usize { | |
| 865 | pub fn pipe2(fd: *[2]i32, flags: u32) usize { | |
| 841 | 866 | return syscall2(SYS_pipe2, @ptrToInt(fd), flags); |
| 842 | 867 | } |
| 843 | 868 | |
| ... | ... | @@ -851,12 +876,17 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 851 | 876 | |
| 852 | 877 | // TODO https://github.com/ziglang/zig/issues/265 |
| 853 | 878 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { |
| 854 | return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); | |
| 879 | return renameat2(AT_FDCWD, old, AT_FDCWD, new, 0); | |
| 880 | } | |
| 881 | ||
| 882 | // TODO https://github.com/ziglang/zig/issues/265 | |
| 883 | pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8, flags: u32) usize { | |
| 884 | return syscall5(SYS_renameat2, @intCast(usize, oldfd), @ptrToInt(oldpath), @intCast(usize, newfd), @ptrToInt(newpath), flags); | |
| 855 | 885 | } |
| 856 | 886 | |
| 857 | 887 | // TODO https://github.com/ziglang/zig/issues/265 |
| 858 | 888 | pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { |
| 859 | return syscall3(SYS_open, @ptrToInt(path), flags, perm); | |
| 889 | return openat(AT_FDCWD, path, flags, perm); | |
| 860 | 890 | } |
| 861 | 891 | |
| 862 | 892 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -865,7 +895,7 @@ pub fn create(path: [*]const u8, perm: usize) usize { |
| 865 | 895 | } |
| 866 | 896 | |
| 867 | 897 | // TODO https://github.com/ziglang/zig/issues/265 |
| 868 | pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { | |
| 898 | pub fn openat(dirfd: i32, path: [*]const u8, flags: u32, mode: usize) usize { | |
| 869 | 899 | return syscall4(SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode); |
| 870 | 900 | } |
| 871 | 901 | |
| ... | ... | @@ -875,7 +905,7 @@ pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: *i32, child_tid: |
| 875 | 905 | } |
| 876 | 906 | |
| 877 | 907 | /// See also `clone` (from the arch-specific include) |
| 878 | pub fn clone2(flags: usize, child_stack_ptr: usize) usize { | |
| 908 | pub fn clone2(flags: u32, child_stack_ptr: usize) usize { | |
| 879 | 909 | return syscall2(SYS_clone, flags, child_stack_ptr); |
| 880 | 910 | } |
| 881 | 911 | |
| ... | ... | @@ -898,7 +928,7 @@ pub fn exit_group(status: i32) noreturn { |
| 898 | 928 | } |
| 899 | 929 | |
| 900 | 930 | pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { |
| 901 | return syscall3(SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags)); | |
| 931 | return syscall3(SYS_getrandom, @ptrToInt(buf), count, flags); | |
| 902 | 932 | } |
| 903 | 933 | |
| 904 | 934 | pub fn kill(pid: i32, sig: i32) usize { |
| ... | ... | @@ -907,7 +937,12 @@ pub fn kill(pid: i32, sig: i32) usize { |
| 907 | 937 | |
| 908 | 938 | // TODO https://github.com/ziglang/zig/issues/265 |
| 909 | 939 | pub fn unlink(path: [*]const u8) usize { |
| 910 | return syscall1(SYS_unlink, @ptrToInt(path)); | |
| 940 | return unlinkat(AT_FDCWD, path, 0); | |
| 941 | } | |
| 942 | ||
| 943 | // TODO https://github.com/ziglang/zig/issues/265 | |
| 944 | pub fn unlinkat(dirfd: i32, path: [*]const u8, flags: u32) usize { | |
| 945 | return syscall3(SYS_unlinkat, @intCast(usize, dirfd), @ptrToInt(path), flags); | |
| 911 | 946 | } |
| 912 | 947 | |
| 913 | 948 | pub fn waitpid(pid: i32, status: *i32, options: i32) usize { |
| ... | ... | @@ -1222,12 +1257,17 @@ pub fn fstat(fd: i32, stat_buf: *Stat) usize { |
| 1222 | 1257 | |
| 1223 | 1258 | // TODO https://github.com/ziglang/zig/issues/265 |
| 1224 | 1259 | pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize { |
| 1225 | return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1260 | return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT); | |
| 1226 | 1261 | } |
| 1227 | 1262 | |
| 1228 | 1263 | // TODO https://github.com/ziglang/zig/issues/265 |
| 1229 | 1264 | pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize { |
| 1230 | return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1265 | return fstatat(AF_FDCWD, pathname, statbuf, AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT); | |
| 1266 | } | |
| 1267 | ||
| 1268 | // TODO https://github.com/ziglang/zig/issues/265 | |
| 1269 | pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize { | |
| 1270 | return syscall4(SYS_fstatat, @intCast(usize, dirfd), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 1231 | 1271 | } |
| 1232 | 1272 | |
| 1233 | 1273 | // TODO https://github.com/ziglang/zig/issues/265 |
| ... | ... | @@ -1318,7 +1358,18 @@ pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize { |
| 1318 | 1358 | } |
| 1319 | 1359 | |
| 1320 | 1360 | pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { |
| 1321 | return syscall4(SYS_epoll_wait, @intCast(usize, epoll_fd), @ptrToInt(events), @intCast(usize, maxevents), @intCast(usize, timeout)); | |
| 1361 | return epoll_pwait(epoll_fd, events, maxevents, timeout, null); | |
| 1362 | } | |
| 1363 | ||
| 1364 | pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { | |
| 1365 | return syscall6(SYS_epoll_pwait, | |
| 1366 | @intCast(usize, epoll_fd), | |
| 1367 | @ptrToInt(events), | |
| 1368 | @intCast(usize, maxevents), | |
| 1369 | @intCast(usize, timeout), | |
| 1370 | @ptrToInt(sigmask), | |
| 1371 | @sizeOf(sigset_t) | |
| 1372 | ); | |
| 1322 | 1373 | } |
| 1323 | 1374 | |
| 1324 | 1375 | pub fn eventfd(count: u32, flags: u32) usize { |
| ... | ... | @@ -1326,7 +1377,7 @@ pub fn eventfd(count: u32, flags: u32) usize { |
| 1326 | 1377 | } |
| 1327 | 1378 | |
| 1328 | 1379 | pub fn timerfd_create(clockid: i32, flags: u32) usize { |
| 1329 | return syscall2(SYS_timerfd_create, @intCast(usize, clockid), @intCast(usize, flags)); | |
| 1380 | return syscall2(SYS_timerfd_create, @intCast(usize, clockid), flags); | |
| 1330 | 1381 | } |
| 1331 | 1382 | |
| 1332 | 1383 | pub const itimerspec = extern struct { |
| ... | ... | @@ -1339,7 +1390,7 @@ pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { |
| 1339 | 1390 | } |
| 1340 | 1391 | |
| 1341 | 1392 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { |
| 1342 | return syscall4(SYS_timerfd_settime, @intCast(usize, fd), @intCast(usize, flags), @ptrToInt(new_value), @ptrToInt(old_value)); | |
| 1393 | return syscall4(SYS_timerfd_settime, @intCast(usize, fd), flags, @ptrToInt(new_value), @ptrToInt(old_value)); | |
| 1343 | 1394 | } |
| 1344 | 1395 | |
| 1345 | 1396 | pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330; |
| ... | ... | @@ -1449,7 +1500,7 @@ pub const cap_user_data_t = extern struct { |
| 1449 | 1500 | }; |
| 1450 | 1501 | |
| 1451 | 1502 | pub fn unshare(flags: usize) usize { |
| 1452 | return syscall1(SYS_unshare, @intCast(usize, flags)); | |
| 1503 | return syscall1(SYS_unshare, flags); | |
| 1453 | 1504 | } |
| 1454 | 1505 | |
| 1455 | 1506 | pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize { |
| ... | ... | @@ -1468,6 +1519,14 @@ pub const inotify_event = extern struct { |
| 1468 | 1519 | //name: [?]u8, |
| 1469 | 1520 | }; |
| 1470 | 1521 | |
| 1522 | pub const dirent64 = extern struct { | |
| 1523 | d_ino: u64, | |
| 1524 | d_off: u64, | |
| 1525 | d_reclen: u16, | |
| 1526 | d_type: u8, | |
| 1527 | d_name: u8, // field address is the address of first byte of name https://github.com/ziglang/zig/issues/173 | |
| 1528 | }; | |
| 1529 | ||
| 1471 | 1530 | test "import" { |
| 1472 | 1531 | if (builtin.os == builtin.Os.linux) { |
| 1473 | 1532 | _ = @import("test.zig"); |
std/os/linux/vdso.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ const cstr = std.cstr; |
| 5 | 5 | const mem = std.mem; |
| 6 | 6 | |
| 7 | 7 | pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 8 | const vdso_addr = std.os.linux_aux_raw[std.elf.AT_SYSINFO_EHDR]; | |
| 8 | const vdso_addr = std.os.linuxGetAuxVal(std.elf.AT_SYSINFO_EHDR); | |
| 9 | 9 | if (vdso_addr == 0) return 0; |
| 10 | 10 | |
| 11 | 11 | const eh = @intToPtr(*elf.Ehdr, vdso_addr); |
std/os/linux/x86_64.zig+9-7| ... | ... | @@ -266,6 +266,8 @@ pub const SYS_mknodat = 259; |
| 266 | 266 | pub const SYS_fchownat = 260; |
| 267 | 267 | pub const SYS_futimesat = 261; |
| 268 | 268 | pub const SYS_newfstatat = 262; |
| 269 | // https://github.com/ziglang/zig/issues/1439 | |
| 270 | pub const SYS_fstatat = 262; | |
| 269 | 271 | pub const SYS_unlinkat = 263; |
| 270 | 272 | pub const SYS_renameat = 264; |
| 271 | 273 | pub const SYS_linkat = 265; |
| ... | ... | @@ -371,6 +373,13 @@ pub const F_GETOWN_EX = 16; |
| 371 | 373 | |
| 372 | 374 | pub const F_GETOWNER_UIDS = 17; |
| 373 | 375 | |
| 376 | pub const AT_FDCWD = -100; | |
| 377 | pub const AT_SYMLINK_NOFOLLOW = 0x100; | |
| 378 | pub const AT_REMOVEDIR = 0x200; | |
| 379 | pub const AT_SYMLINK_FOLLOW = 0x400; | |
| 380 | pub const AT_NO_AUTOMOUNT = 0x800; | |
| 381 | pub const AT_EMPTY_PATH = 0x1000; | |
| 382 | ||
| 374 | 383 | pub const VDSO_USEFUL = true; |
| 375 | 384 | pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; |
| 376 | 385 | pub const VDSO_CGT_VER = "LINUX_2.6"; |
| ... | ... | @@ -521,11 +530,4 @@ pub const timezone = extern struct { |
| 521 | 530 | tz_dsttime: i32, |
| 522 | 531 | }; |
| 523 | 532 | |
| 524 | pub const dirent = extern struct { | |
| 525 | d_ino: usize, | |
| 526 | d_off: usize, | |
| 527 | d_reclen: u16, | |
| 528 | d_name: u8, // field address is the address of first byte of name | |
| 529 | }; | |
| 530 | ||
| 531 | 533 | pub const Elf_Symndx = u32; |
std/special/bootstrap.zig+7-5| ... | ... | @@ -30,6 +30,11 @@ nakedcc fn _start() noreturn { |
| 30 | 30 | : [argc] "=r" (-> [*]usize) |
| 31 | 31 | ); |
| 32 | 32 | }, |
| 33 | builtin.Arch.aarch64v8 => { | |
| 34 | argc_ptr = asm ("mov %[argc], sp" | |
| 35 | : [argc] "=r" (-> [*]usize) | |
| 36 | ); | |
| 37 | }, | |
| 33 | 38 | else => @compileError("unsupported arch"), |
| 34 | 39 | } |
| 35 | 40 | // If LLVM inlines stack variables into _start, they will overwrite |
| ... | ... | @@ -54,11 +59,8 @@ fn posixCallMainAndExit() noreturn { |
| 54 | 59 | const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count]; |
| 55 | 60 | if (builtin.os == builtin.Os.linux) { |
| 56 | 61 | const auxv = @ptrCast([*]usize, envp.ptr + envp_count + 1); |
| 57 | var i: usize = 0; | |
| 58 | while (auxv[i] != 0) : (i += 2) { | |
| 59 | if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1]; | |
| 60 | } | |
| 61 | std.debug.assert(std.os.linux_aux_raw[std.elf.AT_PAGESZ] == std.os.page_size); | |
| 62 | std.os.linux_elf_aux_maybe = @ptrCast([*]std.elf.Auxv, auxv); | |
| 63 | std.debug.assert(std.os.linuxGetAuxVal(std.elf.AT_PAGESZ) == std.os.page_size); | |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | 66 | std.os.posix.exit(callMainWithArgs(argc, argv, envp)); |
std/special/builtin.zig+59-27| ... | ... | @@ -60,7 +60,7 @@ comptime { |
| 60 | 60 | { |
| 61 | 61 | @export("__stack_chk_fail", __stack_chk_fail, builtin.GlobalLinkage.Strong); |
| 62 | 62 | } |
| 63 | if (builtin.os == builtin.Os.linux and builtin.arch == builtin.Arch.x86_64) { | |
| 63 | if (builtin.os == builtin.Os.linux) { | |
| 64 | 64 | @export("clone", clone, builtin.GlobalLinkage.Strong); |
| 65 | 65 | } |
| 66 | 66 | } |
| ... | ... | @@ -72,32 +72,64 @@ extern fn __stack_chk_fail() noreturn { |
| 72 | 72 | // it causes a segfault in release mode. this is a workaround of calling it |
| 73 | 73 | // across .o file boundaries. fix comptime @ptrCast of nakedcc functions. |
| 74 | 74 | nakedcc fn clone() void { |
| 75 | asm volatile ( | |
| 76 | \\ xor %%eax,%%eax | |
| 77 | \\ mov $56,%%al | |
| 78 | \\ mov %%rdi,%%r11 | |
| 79 | \\ mov %%rdx,%%rdi | |
| 80 | \\ mov %%r8,%%rdx | |
| 81 | \\ mov %%r9,%%r8 | |
| 82 | \\ mov 8(%%rsp),%%r10 | |
| 83 | \\ mov %%r11,%%r9 | |
| 84 | \\ and $-16,%%rsi | |
| 85 | \\ sub $8,%%rsi | |
| 86 | \\ mov %%rcx,(%%rsi) | |
| 87 | \\ syscall | |
| 88 | \\ test %%eax,%%eax | |
| 89 | \\ jnz 1f | |
| 90 | \\ xor %%ebp,%%ebp | |
| 91 | \\ pop %%rdi | |
| 92 | \\ call *%%r9 | |
| 93 | \\ mov %%eax,%%edi | |
| 94 | \\ xor %%eax,%%eax | |
| 95 | \\ mov $60,%%al | |
| 96 | \\ syscall | |
| 97 | \\ hlt | |
| 98 | \\1: ret | |
| 99 | \\ | |
| 100 | ); | |
| 75 | if (builtin.arch == builtin.Arch.x86_64) { | |
| 76 | asm volatile ( | |
| 77 | \\ xor %%eax,%%eax | |
| 78 | \\ mov $56,%%al // SYS_clone | |
| 79 | \\ mov %%rdi,%%r11 | |
| 80 | \\ mov %%rdx,%%rdi | |
| 81 | \\ mov %%r8,%%rdx | |
| 82 | \\ mov %%r9,%%r8 | |
| 83 | \\ mov 8(%%rsp),%%r10 | |
| 84 | \\ mov %%r11,%%r9 | |
| 85 | \\ and $-16,%%rsi | |
| 86 | \\ sub $8,%%rsi | |
| 87 | \\ mov %%rcx,(%%rsi) | |
| 88 | \\ syscall | |
| 89 | \\ test %%eax,%%eax | |
| 90 | \\ jnz 1f | |
| 91 | \\ xor %%ebp,%%ebp | |
| 92 | \\ pop %%rdi | |
| 93 | \\ call *%%r9 | |
| 94 | \\ mov %%eax,%%edi | |
| 95 | \\ xor %%eax,%%eax | |
| 96 | \\ mov $60,%%al // SYS_exit | |
| 97 | \\ syscall | |
| 98 | \\ hlt | |
| 99 | \\1: ret | |
| 100 | \\ | |
| 101 | ); | |
| 102 | } else if (builtin.arch == builtin.Arch.aarch64v8) { | |
| 103 | // __clone(func, stack, flags, arg, ptid, tls, ctid) | |
| 104 | // x0, x1, w2, x3, x4, x5, x6 | |
| 105 | ||
| 106 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | |
| 107 | // x8, x0, x1, x2, x3, x4 | |
| 108 | asm volatile ( | |
| 109 | \\ // align stack and save func,arg | |
| 110 | \\ and x1,x1,#-16 | |
| 111 | \\ stp x0,x3,[x1,#-16]! | |
| 112 | \\ | |
| 113 | \\ // syscall | |
| 114 | \\ uxtw x0,w2 | |
| 115 | \\ mov x2,x4 | |
| 116 | \\ mov x3,x5 | |
| 117 | \\ mov x4,x6 | |
| 118 | \\ mov x8,#220 // SYS_clone | |
| 119 | \\ svc #0 | |
| 120 | \\ | |
| 121 | \\ cbz x0,1f | |
| 122 | \\ // parent | |
| 123 | \\ ret | |
| 124 | \\ // child | |
| 125 | \\1: ldp x1,x0,[sp],#16 | |
| 126 | \\ blr x1 | |
| 127 | \\ mov x8,#93 // SYS_exit | |
| 128 | \\ svc #0 | |
| 129 | ); | |
| 130 | } else { | |
| 131 | @compileError("Implement clone() for this arch."); | |
| 132 | } | |
| 101 | 133 | } |
| 102 | 134 | |
| 103 | 135 | const math = @import("../math/index.zig"); |