| author | |
| committer | |
| log | 5f3d9e0b7a67b8a23b659ca7dada8641f55b8503 |
| tree | 7b369b303aadd0be6c8354fa3277cd8c6dd57099 |
| parent | f29bdd6746691d0a547140e435056a000419480f |
| parent | ae10adb6ef7182352c6176a135e181ba70c81212 |
| signature |
More `riscv32-linux` port work6 files changed, 85 insertions(+), 5 deletions(-)
lib/std/dynamic_library.zig+2-1| ... | ... | @@ -215,7 +215,8 @@ pub const ElfDynLib = struct { |
| 215 | 215 | const fd = try resolveFromName(path); |
| 216 | 216 | defer posix.close(fd); |
| 217 | 217 | |
| 218 | const stat = try posix.fstat(fd); | |
| 218 | const file: std.fs.File = .{ .handle = fd }; | |
| 219 | const stat = try file.stat(); | |
| 219 | 220 | const size = std.math.cast(usize, stat.size) orelse return error.FileTooBig; |
| 220 | 221 | |
| 221 | 222 | // This one is to read the ELF info. We do more mmapping later |
lib/std/os/linux.zig+19-2| ... | ... | @@ -1456,6 +1456,16 @@ pub fn clock_settime(clk_id: i32, tp: *const timespec) usize { |
| 1456 | 1456 | return syscall2(.clock_settime, @as(usize, @bitCast(@as(isize, clk_id))), @intFromPtr(tp)); |
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | pub fn clock_nanosleep(clockid: clockid_t, flags: TIMER, request: *const timespec, remain: ?*timespec) usize { | |
| 1460 | return syscall4( | |
| 1461 | .clock_nanosleep, | |
| 1462 | @intFromEnum(clockid), | |
| 1463 | @as(u32, @bitCast(flags)), | |
| 1464 | @intFromPtr(request), | |
| 1465 | @intFromPtr(remain), | |
| 1466 | ); | |
| 1467 | } | |
| 1468 | ||
| 1459 | 1469 | pub fn gettimeofday(tv: ?*timeval, tz: ?*timezone) usize { |
| 1460 | 1470 | return syscall2(.gettimeofday, @intFromPtr(tv), @intFromPtr(tz)); |
| 1461 | 1471 | } |
| ... | ... | @@ -1465,7 +1475,9 @@ pub fn settimeofday(tv: *const timeval, tz: *const timezone) usize { |
| 1465 | 1475 | } |
| 1466 | 1476 | |
| 1467 | 1477 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { |
| 1468 | return syscall2(.nanosleep, @intFromPtr(req), @intFromPtr(rem)); | |
| 1478 | if (native_arch == .riscv32) { | |
| 1479 | @compileError("No nanosleep syscall on this architecture."); | |
| 1480 | } else return syscall2(.nanosleep, @intFromPtr(req), @intFromPtr(rem)); | |
| 1469 | 1481 | } |
| 1470 | 1482 | |
| 1471 | 1483 | pub fn pause() usize { |
| ... | ... | @@ -4525,6 +4537,11 @@ pub const clockid_t = enum(u32) { |
| 4525 | 4537 | _, |
| 4526 | 4538 | }; |
| 4527 | 4539 | |
| 4540 | pub const TIMER = packed struct(u32) { | |
| 4541 | ABSTIME: bool, | |
| 4542 | _: u31 = 0, | |
| 4543 | }; | |
| 4544 | ||
| 4528 | 4545 | pub const CSIGNAL = 0x000000ff; |
| 4529 | 4546 | |
| 4530 | 4547 | pub const CLONE = struct { |
| ... | ... | @@ -7452,7 +7469,7 @@ pub const kernel_timespec = extern struct { |
| 7452 | 7469 | }; |
| 7453 | 7470 | |
| 7454 | 7471 | // https://github.com/ziglang/zig/issues/4726#issuecomment-2190337877 |
| 7455 | pub const timespec = if (!builtin.link_libc and native_arch == .riscv32) kernel_timespec else extern struct { | |
| 7472 | pub const timespec = if (native_arch == .riscv32) kernel_timespec else extern struct { | |
| 7456 | 7473 | sec: isize, |
| 7457 | 7474 | nsec: isize, |
| 7458 | 7475 | }; |
lib/std/os/linux/riscv32.zig+31-2| ... | ... | @@ -212,8 +212,37 @@ pub const msghdr_const = extern struct { |
| 212 | 212 | flags: i32, |
| 213 | 213 | }; |
| 214 | 214 | |
| 215 | /// No `Stat` structure on this platform, only `Statx`. | |
| 216 | pub const Stat = void; | |
| 215 | // The `stat` definition used by the Linux kernel. | |
| 216 | pub const Stat = extern struct { | |
| 217 | dev: dev_t, | |
| 218 | ino: ino_t, | |
| 219 | mode: mode_t, | |
| 220 | nlink: nlink_t, | |
| 221 | uid: uid_t, | |
| 222 | gid: gid_t, | |
| 223 | rdev: dev_t, | |
| 224 | __pad: usize, | |
| 225 | size: off_t, | |
| 226 | blksize: blksize_t, | |
| 227 | __pad2: i32, | |
| 228 | blocks: blkcnt_t, | |
| 229 | atim: timespec, | |
| 230 | mtim: timespec, | |
| 231 | ctim: timespec, | |
| 232 | __unused: [2]u32, | |
| 233 | ||
| 234 | pub fn atime(self: @This()) timespec { | |
| 235 | return self.atim; | |
| 236 | } | |
| 237 | ||
| 238 | pub fn mtime(self: @This()) timespec { | |
| 239 | return self.mtim; | |
| 240 | } | |
| 241 | ||
| 242 | pub fn ctime(self: @This()) timespec { | |
| 243 | return self.ctim; | |
| 244 | } | |
| 245 | }; | |
| 217 | 246 | |
| 218 | 247 | pub const Elf_Symndx = u32; |
| 219 | 248 |
lib/std/posix/test.zig+4| ... | ... | @@ -349,6 +349,7 @@ test "linkat with different directories" { |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | test "fstatat" { |
| 352 | if (builtin.cpu.arch == .riscv32 and builtin.os.tag == .linux and !builtin.link_libc) return error.SkipZigTest; // No `fstatat()`. | |
| 352 | 353 | // enable when `fstat` and `fstatat` are implemented on Windows |
| 353 | 354 | if (native_os == .windows) return error.SkipZigTest; |
| 354 | 355 | |
| ... | ... | @@ -1264,6 +1265,9 @@ test "fchmodat smoke test" { |
| 1264 | 1265 | 0o644, |
| 1265 | 1266 | ); |
| 1266 | 1267 | posix.close(fd); |
| 1268 | ||
| 1269 | if (builtin.cpu.arch == .riscv32 and builtin.os.tag == .linux and !builtin.link_libc) return error.SkipZigTest; // No `fstatat()`. | |
| 1270 | ||
| 1267 | 1271 | try posix.symlinkat("regfile", tmp.dir.fd, "symlink"); |
| 1268 | 1272 | const sym_mode = blk: { |
| 1269 | 1273 | const st = try posix.fstatat(tmp.dir.fd, "symlink", posix.AT.SYMLINK_NOFOLLOW); |
lib/std/time.zig+28| ... | ... | @@ -50,6 +50,34 @@ pub fn sleep(nanoseconds: u64) void { |
| 50 | 50 | |
| 51 | 51 | const s = nanoseconds / ns_per_s; |
| 52 | 52 | const ns = nanoseconds % ns_per_s; |
| 53 | ||
| 54 | // Newer kernel ports don't have old `nanosleep()` and `clock_nanosleep()` has been around | |
| 55 | // since Linux 2.6 and glibc 2.1 anyway. | |
| 56 | if (builtin.os.tag == .linux) { | |
| 57 | const linux = std.os.linux; | |
| 58 | ||
| 59 | var req: linux.timespec = .{ | |
| 60 | .sec = std.math.cast(linux.time_t, s) orelse std.math.maxInt(linux.time_t), | |
| 61 | .nsec = std.math.cast(linux.time_t, ns) orelse std.math.maxInt(linux.time_t), | |
| 62 | }; | |
| 63 | var rem: linux.timespec = undefined; | |
| 64 | ||
| 65 | while (true) { | |
| 66 | switch (linux.E.init(linux.clock_nanosleep(.MONOTONIC, .{ .ABSTIME = false }, &req, &rem))) { | |
| 67 | .SUCCESS => return, | |
| 68 | .INTR => { | |
| 69 | req = rem; | |
| 70 | continue; | |
| 71 | }, | |
| 72 | .FAULT, | |
| 73 | .INVAL, | |
| 74 | .OPNOTSUPP, | |
| 75 | => unreachable, | |
| 76 | else => return, | |
| 77 | } | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 53 | 81 | posix.nanosleep(s, ns); |
| 54 | 82 | } |
| 55 | 83 |
src/codegen/llvm.zig+1| ... | ... | @@ -12398,6 +12398,7 @@ fn backendSupportsF16(target: std.Target) bool { |
| 12398 | 12398 | .mipsel, |
| 12399 | 12399 | .mips64, |
| 12400 | 12400 | .mips64el, |
| 12401 | .riscv32, | |
| 12401 | 12402 | .s390x, |
| 12402 | 12403 | => false, |
| 12403 | 12404 | .aarch64, |