fix windows

This commit is contained in:
Mitchell Hashimoto
2025-03-12 16:14:23 -07:00
parent 907ed239a1
commit fc21444f2d
4 changed files with 18 additions and 15 deletions

View File

@ -193,11 +193,11 @@ fn startPosix(self: *Command, arena: Allocator) !void {
} }
fn startWindows(self: *Command, arena: Allocator) !void { fn startWindows(self: *Command, arena: Allocator) !void {
const application_w = try std.unicode.utf8ToUtf16LeWithNull(arena, self.path); const application_w = try std.unicode.utf8ToUtf16LeAllocZ(arena, self.path);
const cwd_w = if (self.cwd) |cwd| try std.unicode.utf8ToUtf16LeWithNull(arena, cwd) else null; const cwd_w = if (self.cwd) |cwd| try std.unicode.utf8ToUtf16LeAllocZ(arena, cwd) else null;
const command_line_w = if (self.args.len > 0) b: { const command_line_w = if (self.args.len > 0) b: {
const command_line = try windowsCreateCommandLine(arena, self.args); const command_line = try windowsCreateCommandLine(arena, self.args);
break :b try std.unicode.utf8ToUtf16LeWithNull(arena, command_line); break :b try std.unicode.utf8ToUtf16LeAllocZ(arena, command_line);
} else null; } else null;
const env_w = if (self.env) |env_map| try createWindowsEnvBlock(arena, env_map) else null; const env_w = if (self.env) |env_map| try createWindowsEnvBlock(arena, env_map) else null;

View File

@ -10,7 +10,8 @@ pub const rlimit = if (@hasDecl(posix.system, "rlimit")) posix.rlimit else struc
/// need to do this because each window consumes at least a handful of fds. /// need to do this because each window consumes at least a handful of fds.
/// This is extracted from the Zig compiler source code. /// This is extracted from the Zig compiler source code.
pub fn fixMaxFiles() ?rlimit { pub fn fixMaxFiles() ?rlimit {
if (!@hasDecl(posix.system, "rlimit")) return null; if (!@hasDecl(posix.system, "rlimit") or
posix.system.rlimit == void) return null;
const old = posix.getrlimit(.NOFILE) catch { const old = posix.getrlimit(.NOFILE) catch {
log.warn("failed to query file handle limit, may limit max windows", .{}); log.warn("failed to query file handle limit, may limit max windows", .{});

View File

@ -6,6 +6,8 @@ const windows = std.os.windows;
pub const kernel32 = windows.kernel32; pub const kernel32 = windows.kernel32;
pub const unexpectedError = windows.unexpectedError; pub const unexpectedError = windows.unexpectedError;
pub const OpenFile = windows.OpenFile; pub const OpenFile = windows.OpenFile;
pub const CloseHandle = windows.CloseHandle;
pub const GetCurrentProcessId = windows.GetCurrentProcessId;
pub const SetHandleInformation = windows.SetHandleInformation; pub const SetHandleInformation = windows.SetHandleInformation;
pub const DWORD = windows.DWORD; pub const DWORD = windows.DWORD;
pub const FILE_ATTRIBUTE_NORMAL = windows.FILE_ATTRIBUTE_NORMAL; pub const FILE_ATTRIBUTE_NORMAL = windows.FILE_ATTRIBUTE_NORMAL;

View File

@ -275,7 +275,7 @@ const WindowsPty = struct {
&pipe_path_buf, &pipe_path_buf,
"\\\\.\\pipe\\LOCAL\\ghostty-pty-{d}-{d}", "\\\\.\\pipe\\LOCAL\\ghostty-pty-{d}-{d}",
.{ .{
windows.kernel32.GetCurrentProcessId(), windows.GetCurrentProcessId(),
pipe_name_counter.fetchAdd(1, .monotonic), pipe_name_counter.fetchAdd(1, .monotonic),
}, },
) catch unreachable; ) catch unreachable;
@ -308,7 +308,7 @@ const WindowsPty = struct {
if (pty.in_pipe == windows.INVALID_HANDLE_VALUE) { if (pty.in_pipe == windows.INVALID_HANDLE_VALUE) {
return windows.unexpectedError(windows.kernel32.GetLastError()); return windows.unexpectedError(windows.kernel32.GetLastError());
} }
errdefer _ = windows.kernel32.CloseHandle(pty.in_pipe); errdefer _ = windows.CloseHandle(pty.in_pipe);
var security_attributes_read = security_attributes; var security_attributes_read = security_attributes;
pty.in_pipe_pty = windows.kernel32.CreateFileW( pty.in_pipe_pty = windows.kernel32.CreateFileW(
@ -323,7 +323,7 @@ const WindowsPty = struct {
if (pty.in_pipe_pty == windows.INVALID_HANDLE_VALUE) { if (pty.in_pipe_pty == windows.INVALID_HANDLE_VALUE) {
return windows.unexpectedError(windows.kernel32.GetLastError()); return windows.unexpectedError(windows.kernel32.GetLastError());
} }
errdefer _ = windows.kernel32.CloseHandle(pty.in_pipe_pty); errdefer _ = windows.CloseHandle(pty.in_pipe_pty);
// The in_pipe needs to be created as a named pipe, since anonymous // The in_pipe needs to be created as a named pipe, since anonymous
// pipes created with CreatePipe do not support overlapped operations, // pipes created with CreatePipe do not support overlapped operations,
@ -336,16 +336,16 @@ const WindowsPty = struct {
// return windows.unexpectedError(windows.kernel32.GetLastError()); // return windows.unexpectedError(windows.kernel32.GetLastError());
// } // }
// errdefer { // errdefer {
// _ = windows.kernel32.CloseHandle(pty.in_pipe_pty); // _ = windows.CloseHandle(pty.in_pipe_pty);
// _ = windows.kernel32.CloseHandle(pty.in_pipe); // _ = windows.CloseHandle(pty.in_pipe);
// } // }
if (windows.exp.kernel32.CreatePipe(&pty.out_pipe, &pty.out_pipe_pty, null, 0) == 0) { if (windows.exp.kernel32.CreatePipe(&pty.out_pipe, &pty.out_pipe_pty, null, 0) == 0) {
return windows.unexpectedError(windows.kernel32.GetLastError()); return windows.unexpectedError(windows.kernel32.GetLastError());
} }
errdefer { errdefer {
_ = windows.kernel32.CloseHandle(pty.out_pipe); _ = windows.CloseHandle(pty.out_pipe);
_ = windows.kernel32.CloseHandle(pty.out_pipe_pty); _ = windows.CloseHandle(pty.out_pipe_pty);
} }
try windows.SetHandleInformation(pty.in_pipe, windows.HANDLE_FLAG_INHERIT, 0); try windows.SetHandleInformation(pty.in_pipe, windows.HANDLE_FLAG_INHERIT, 0);
@ -367,10 +367,10 @@ const WindowsPty = struct {
} }
pub fn deinit(self: *Pty) void { pub fn deinit(self: *Pty) void {
_ = windows.kernel32.CloseHandle(self.in_pipe_pty); _ = windows.CloseHandle(self.in_pipe_pty);
_ = windows.kernel32.CloseHandle(self.in_pipe); _ = windows.CloseHandle(self.in_pipe);
_ = windows.kernel32.CloseHandle(self.out_pipe_pty); _ = windows.CloseHandle(self.out_pipe_pty);
_ = windows.kernel32.CloseHandle(self.out_pipe); _ = windows.CloseHandle(self.out_pipe);
_ = windows.exp.kernel32.ClosePseudoConsole(self.pseudo_console); _ = windows.exp.kernel32.ClosePseudoConsole(self.pseudo_console);
self.* = undefined; self.* = undefined;
} }