Skip to content

winterm: replace more code for golang.org/x/windows - #53

Merged
Brian Goff (cpuguy83) merged 7 commits into
Azure:masterfrom
thaJeztah:more_x_win
Oct 13, 2026
Merged

Brian Goff (cpuguy83) merged 7 commits into
Azure:masterfrom
thaJeztah:more_x_win

Conversation

@thaJeztah

@thaJeztah Sebastiaan van Stijn (thaJeztah) commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

winterm: replace "use" for runtime.KeepAlive

Same purpose, but more idiomatic.

winterm: use windows.NewLazyDLL instead of syscall.NewLazyDLL

The syscall variant comes with a warning;

LazyDLL is subject to the same DLL preloading attacks as documented on LoadDLL.

Use LazyDLL in golang.org/x/sys/windows for a secure way to load system DLLs.

It does have special handling for kernel32.dll though, so in practice,
there's no real difference, but as we're using more of golang.org/x/windows
already, there's no harm in switching.

winterm: implement GetConsoleMode, SetConsoleMode with x/sys/windows

Both are now implemented in golang.org/x/sys/windows.

winterm: alias consts to their golang.org/x/sys/windows counterparts

Key events require an updated version of golang.org/x/sys v0.33.0, which
added them in golang/sys@8e9e046

Keep WAIT_TIMEOUT untyped for compatibility with the previous API,
as windows.WAIT_TIMEOUT is typed as syscall.Errno.

winterm: implement WaitForSingleObject with x/sys/windows

winterm: implement SetConsoleCursorPosition with x/sys/windows

This method is now implemented in golang.org/x/sys/windows, but our local
struct definitions currently implement [fmt.Stringer], so we cannot make
them a straight alias.

Instead, definining them as concrete type, but use the type from x/windows,
then convert them.

winterm: implement GetConsoleScreenBufferInfo with x/sys/windows

This method is now implemented in golang.org/x/sys/windows, but our local
struct definitions currently implement [fmt.Stringer], so we cannot make
them a straight alias.

Instead, use x/windows for the syscall, then convert the result.

Same purpose, but more idiomatic.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The syscall variant comes with a warning;

> LazyDLL is subject to the same DLL preloading attacks as documented on LoadDLL.
>
> Use LazyDLL in `golang.org/x/sys/windows` for a secure way to load system DLLs.

It does have special handling for `kernel32.dll` though, so in practice,
there's no real difference, but as we're using more of golang.org/x/windows
already, there's no harm in switching.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Both are now implemented in golang.org/x/sys/windows.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Key events require an updated version of golang.org/x/sys v0.33.0, which
added them in golang/sys@8e9e046

Keep WAIT_TIMEOUT untyped for compatibility with the previous API,
as windows.WAIT_TIMEOUT is typed as syscall.Errno.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This method is now implemented in golang.org/x/sys/windows, but our local
struct definitions currently implement [fmt.Stringer], so we cannot make
them a straight alias.

Instead, definining them as concrete type, but use the type from x/windows,
then convert them.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This method is now implemented in golang.org/x/sys/windows, but our local
struct definitions currently implement [fmt.Stringer], so we cannot make
them a straight alias.

Instead, use x/windows for the syscall, then convert the result.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@cpuguy83
Brian Goff (cpuguy83) merged commit fca74af into Azure:master Oct 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants