Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/std/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ fn preadNoEof(file: std.fs.File, buf: []u8, offset: u64) !void {
error.InputOutput => return error.FileSystem,
error.Unexpected => return error.Unexpected,
error.WouldBlock => return error.Unexpected,
error.NotOpenForReading => return error.Unexpected,
error.AccessDenied => return error.Unexpected,
};
if (len == 0) return error.UnexpectedEndOfFile;
Expand Down
36 changes: 19 additions & 17 deletions lib/std/os.zig
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ pub const ReadError = error{
BrokenPipe,
ConnectionResetByPeer,
ConnectionTimedOut,
NotOpenForReading,

/// This error occurs when no global event loop is configured,
/// and reading from the file descriptor would block.
Expand Down Expand Up @@ -332,7 +333,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
wasi.EINVAL => unreachable,
wasi.EFAULT => unreachable,
wasi.EAGAIN => unreachable,
wasi.EBADF => unreachable, // Always a race condition.
wasi.EBADF => return error.NotOpenForReading, // Can be a race condition.
wasi.EIO => return error.InputOutput,
wasi.EISDIR => return error.IsDir,
wasi.ENOBUFS => return error.SystemResources,
Expand Down Expand Up @@ -364,7 +365,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
} else {
return error.WouldBlock;
},
EBADF => unreachable, // Always a race condition.
EBADF => return error.NotOpenForReading, // Can be a race condition.
EIO => return error.InputOutput,
EISDIR => return error.IsDir,
ENOBUFS => return error.SystemResources,
Expand Down Expand Up @@ -402,7 +403,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
wasi.EINVAL => unreachable,
wasi.EFAULT => unreachable,
wasi.EAGAIN => unreachable, // currently not support in WASI
wasi.EBADF => unreachable, // always a race condition
wasi.EBADF => return error.NotOpenForReading, // can be a race condition
wasi.EIO => return error.InputOutput,
wasi.EISDIR => return error.IsDir,
wasi.ENOBUFS => return error.SystemResources,
Expand All @@ -426,7 +427,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize {
} else {
return error.WouldBlock;
},
EBADF => unreachable, // always a race condition
EBADF => return error.NotOpenForReading, // can be a race condition
EIO => return error.InputOutput,
EISDIR => return error.IsDir,
ENOBUFS => return error.SystemResources,
Expand Down Expand Up @@ -463,7 +464,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
wasi.EINVAL => unreachable,
wasi.EFAULT => unreachable,
wasi.EAGAIN => unreachable,
wasi.EBADF => unreachable, // Always a race condition.
wasi.EBADF => return error.NotOpenForReading, // Can be a race condition.
wasi.EIO => return error.InputOutput,
wasi.EISDIR => return error.IsDir,
wasi.ENOBUFS => return error.SystemResources,
Expand All @@ -490,7 +491,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize {
} else {
return error.WouldBlock;
},
EBADF => unreachable, // Always a race condition.
EBADF => return error.NotOpenForReading, // Can be a race condition.
EIO => return error.InputOutput,
EISDIR => return error.IsDir,
ENOBUFS => return error.SystemResources,
Expand Down Expand Up @@ -607,7 +608,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
wasi.EINVAL => unreachable,
wasi.EFAULT => unreachable,
wasi.EAGAIN => unreachable,
wasi.EBADF => unreachable, // always a race condition
wasi.EBADF => return error.NotOpenForReading, // can be a race condition
wasi.EIO => return error.InputOutput,
wasi.EISDIR => return error.IsDir,
wasi.ENOBUFS => return error.SystemResources,
Expand Down Expand Up @@ -635,7 +636,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize {
} else {
return error.WouldBlock;
},
EBADF => unreachable, // always a race condition
EBADF => return error.NotOpenForReading, // can be a race condition
EIO => return error.InputOutput,
EISDIR => return error.IsDir,
ENOBUFS => return error.SystemResources,
Expand All @@ -660,6 +661,7 @@ pub const WriteError = error{
BrokenPipe,
SystemResources,
OperationAborted,
NotOpenForWriting,

/// This error occurs when no global event loop is configured,
/// and reading from the file descriptor would block.
Expand Down Expand Up @@ -704,7 +706,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
wasi.EINVAL => unreachable,
wasi.EFAULT => unreachable,
wasi.EAGAIN => unreachable,
wasi.EBADF => unreachable, // Always a race condition.
wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
wasi.EDQUOT => return error.DiskQuota,
wasi.EFBIG => return error.FileTooBig,
Expand Down Expand Up @@ -736,7 +738,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
} else {
return error.WouldBlock;
},
EBADF => unreachable, // Always a race condition.
EBADF => return error.NotOpenForWriting, // can be a race condition.
EDESTADDRREQ => unreachable, // `connect` was never called.
EDQUOT => return error.DiskQuota,
EFBIG => return error.FileTooBig,
Expand Down Expand Up @@ -782,7 +784,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
wasi.EINVAL => unreachable,
wasi.EFAULT => unreachable,
wasi.EAGAIN => unreachable,
wasi.EBADF => unreachable, // Always a race condition.
wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
wasi.EDQUOT => return error.DiskQuota,
wasi.EFBIG => return error.FileTooBig,
Expand All @@ -809,7 +811,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize {
} else {
return error.WouldBlock;
},
EBADF => unreachable, // Always a race condition.
EBADF => return error.NotOpenForWriting, // Can be a race condition.
EDESTADDRREQ => unreachable, // `connect` was never called.
EDQUOT => return error.DiskQuota,
EFBIG => return error.FileTooBig,
Expand Down Expand Up @@ -862,7 +864,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
wasi.EINVAL => unreachable,
wasi.EFAULT => unreachable,
wasi.EAGAIN => unreachable,
wasi.EBADF => unreachable, // Always a race condition.
wasi.EBADF => return error.NotOpenForWriting, // can be a race condition.
wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
wasi.EDQUOT => return error.DiskQuota,
wasi.EFBIG => return error.FileTooBig,
Expand Down Expand Up @@ -898,7 +900,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
} else {
return error.WouldBlock;
},
EBADF => unreachable, // Always a race condition.
EBADF => return error.NotOpenForWriting, // Can be a race condition.
EDESTADDRREQ => unreachable, // `connect` was never called.
EDQUOT => return error.DiskQuota,
EFBIG => return error.FileTooBig,
Expand Down Expand Up @@ -956,7 +958,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
wasi.EINVAL => unreachable,
wasi.EFAULT => unreachable,
wasi.EAGAIN => unreachable,
wasi.EBADF => unreachable, // Always a race condition.
wasi.EBADF => return error.NotOpenForWriting, // Can be a race condition.
wasi.EDESTADDRREQ => unreachable, // `connect` was never called.
wasi.EDQUOT => return error.DiskQuota,
wasi.EFBIG => return error.FileTooBig,
Expand Down Expand Up @@ -986,7 +988,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz
} else {
return error.WouldBlock;
},
EBADF => unreachable, // Always a race condition.
EBADF => return error.NotOpenForWriting, // Can be a race condition.
EDESTADDRREQ => unreachable, // `connect` was never called.
EDQUOT => return error.DiskQuota,
EFBIG => return error.FileTooBig,
Expand Down Expand Up @@ -1184,7 +1186,7 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void {
EBUSY, EINTR => continue,
EMFILE => return error.ProcessFdQuotaExceeded,
EINVAL => unreachable, // invalid parameters passed to dup2
EBADF => unreachable, // always a race condition
EBADF => unreachable, // invalid file descriptor
else => |err| return unexpectedErrno(err),
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/std/zig/system.zig
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ pub const NativeTargetInfo = struct {
const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
error.OperationAborted => unreachable, // Windows-only
error.WouldBlock => unreachable, // Did not request blocking mode
error.NotOpenForReading => unreachable,
error.SystemResources => return error.SystemResources,
error.IsDir => return error.UnableToReadElfFile,
error.BrokenPipe => return error.UnableToReadElfFile,
Expand Down
2 changes: 2 additions & 0 deletions src-self-hosted/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ const FmtError = error{
LinkQuotaExceeded,
FileBusy,
EndOfStream,
NotOpenForWriting,
} || fs.File.OpenError;

fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool, dir: fs.Dir, sub_path: []const u8) FmtError!void {
Expand Down Expand Up @@ -761,6 +762,7 @@ fn fmtPathFile(
const source_code = source_file.readAllAlloc(fmt.gpa, stat.size, max_src_size) catch |err| switch (err) {
error.ConnectionResetByPeer => unreachable,
error.ConnectionTimedOut => unreachable,
error.NotOpenForReading => unreachable,
else => |e| return e,
};
source_file.close();
Expand Down
4 changes: 4 additions & 0 deletions src-self-hosted/stage2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {
const c_out_stream = std.io.cOutStream(output_file);
_ = std.zig.render(std.heap.c_allocator, c_out_stream, tree) catch |e| switch (e) {
error.WouldBlock => unreachable, // stage1 opens stuff in exclusively blocking mode
error.NotOpenForWriting => unreachable,
error.SystemResources => return .SystemResources,
error.OperationAborted => return .OperationAborted,
error.BrokenPipe => return .BrokenPipe,
Expand Down Expand Up @@ -585,6 +586,8 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [
error.SystemResources => return .SystemResources,
error.OperationAborted => return .OperationAborted,
error.WouldBlock => unreachable,
error.NotOpenForWriting => unreachable,
error.NotOpenForReading => unreachable,
error.Unexpected => return .Unexpected,
error.EndOfStream => return .EndOfFile,
error.IsDir => return .IsDir,
Expand Down Expand Up @@ -640,6 +643,7 @@ export fn stage2_libc_render(stage1_libc: *Stage2LibCInstallation, output_file:
const c_out_stream = std.io.cOutStream(output_file);
libc.render(c_out_stream) catch |err| switch (err) {
error.WouldBlock => unreachable, // stage1 opens stuff in exclusively blocking mode
error.NotOpenForWriting => unreachable,
error.SystemResources => return .SystemResources,
error.OperationAborted => return .OperationAborted,
error.BrokenPipe => return .BrokenPipe,
Expand Down