Open The-King-of-Toasters opened 8 months ago
I have a prototype of a CreatePipe
impl that uses the Native API, works great when single-threaded. Unfortunately everything fails hard when using it via the zig build runner. I'll put it up on a draft PR and hopefully I can crack this case; my windbg
-foo is failing me.
Edit: I'm silly and passed the wrong flags.
CreatePipe and CreateNamedPipe are used by
child_process
to... create anonymous and named pipes for redirecting i/o. From my research, these are abstractions aroundNtCreateNamedPipeFile
andNtOpenFile
for the writing end. As per #1840, we should prefer using these APIs over kernel32 ones.CreatePipe
Here is wine's implementation. Using
NtTrace
we see the same calls being made, just out of order:Example Program
```zig var in: HANDLE = undefined; var out: HANDLE = undefined; const res = CreatePipe(&in, &out, null, 1024); if (res == 0) std.debug.panic("huh, {}", .{kernel32.GetLastError()}); defer { std.os.close(in); std.os.close(out); } ```Some improvements we could make:
FALSE/0
with proper constants (e.g.FILE_PIPE_BYTE_STREAM_MODE
).Not that I cannot find these pipes under the pipe device directory (
ls \\.\pipe\
in powershell), unlike proper named pipes.CreateNamedPipe
Again, here is Wine's impl and a trace log.
Sample
```zig const file = std.unicode.utf8ToUtf16LeStringLiteral("\\\\.\\pipe\\my_pipe"); const read_handle = windows.kernel32.CreateNamedPipeW( file.ptr, windows.PIPE_ACCESS_INBOUND | windows.FILE_FLAG_OVERLAPPED, windows.PIPE_TYPE_BYTE, 1, 4096, 4096, 0, null, ); defer std.os.close(read_handle); ```Pretty close to the real thing.