From 59711becc74911ba251001de81bbac2a53e81b9f Mon Sep 17 00:00:00 2001 From: StrangeBug Date: Fri, 22 May 2020 20:24:16 +0200 Subject: [PATCH 1/2] Add handler for INVALID_HANDLE to prevent infinite loop when stderr is not available. --- lib/std/os/windows.zig | 2 ++ src-self-hosted/stage2.zig | 3 +++ 2 files changed, 5 insertions(+) diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index c93feb20d7..c2decaf208 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -469,6 +469,7 @@ pub const WriteFileError = error{ SystemResources, OperationAborted, BrokenPipe, + InvalidFd, Unexpected, }; @@ -542,6 +543,7 @@ pub fn WriteFile( .NOT_ENOUGH_QUOTA => return error.SystemResources, .IO_PENDING => unreachable, .BROKEN_PIPE => return error.BrokenPipe, + .INVALID_HANDLE => return error.NotOpenForWriting, else => |err| return unexpectedError(err), } } diff --git a/src-self-hosted/stage2.zig b/src-self-hosted/stage2.zig index 30d2ea44db..148001c575 100644 --- a/src-self-hosted/stage2.zig +++ b/src-self-hosted/stage2.zig @@ -164,6 +164,7 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error { error.OutOfMemory => return .OutOfMemory, error.Unexpected => return .Unexpected, error.InputOutput => return .FileSystem, + error.InvalidFd => return .FileSystem, }; return .None; } @@ -635,6 +636,7 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [ error.NotDir => return .NotDir, error.DeviceBusy => return .DeviceBusy, error.FileLocksNotSupported => unreachable, + error.InvalidFd => return .FileSystem, }; stage1_libc.initFromStage2(libc); return .None; @@ -679,6 +681,7 @@ export fn stage2_libc_render(stage1_libc: *Stage2LibCInstallation, output_file: error.AccessDenied => return .AccessDenied, error.Unexpected => return .Unexpected, error.InputOutput => return .FileSystem, + error.InvalidFd => return .FileSystem, }; return .None; } From 23c427b5fbd0e83b08d83a00cd343ff9bc4c1824 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 19 Aug 2020 20:51:06 -0700 Subject: [PATCH 2/2] windows: match the same error code for EBADF --- lib/std/os/windows.zig | 2 +- src-self-hosted/stage2.zig | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index c2decaf208..2f2369a458 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -469,7 +469,7 @@ pub const WriteFileError = error{ SystemResources, OperationAborted, BrokenPipe, - InvalidFd, + NotOpenForWriting, Unexpected, }; diff --git a/src-self-hosted/stage2.zig b/src-self-hosted/stage2.zig index 148001c575..30d2ea44db 100644 --- a/src-self-hosted/stage2.zig +++ b/src-self-hosted/stage2.zig @@ -164,7 +164,6 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error { error.OutOfMemory => return .OutOfMemory, error.Unexpected => return .Unexpected, error.InputOutput => return .FileSystem, - error.InvalidFd => return .FileSystem, }; return .None; } @@ -636,7 +635,6 @@ export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [ error.NotDir => return .NotDir, error.DeviceBusy => return .DeviceBusy, error.FileLocksNotSupported => unreachable, - error.InvalidFd => return .FileSystem, }; stage1_libc.initFromStage2(libc); return .None; @@ -681,7 +679,6 @@ export fn stage2_libc_render(stage1_libc: *Stage2LibCInstallation, output_file: error.AccessDenied => return .AccessDenied, error.Unexpected => return .Unexpected, error.InputOutput => return .FileSystem, - error.InvalidFd => return .FileSystem, }; return .None; }