windows/mkwinsyscall: read 32-bit results from the low half of the return register

On 64-bit Windows the upper 32 bits of the return register are
undefined for 32-bit return types (BOOL, DWORD, LSTATUS, NTSTATUS,
HRESULT). Hooked or otherwise non-conforming implementations can leave
garbage there, which the generated code then mistook for a failure or
for a different error code.

Read error and bool results through uint32 so only the defined bits are
used, including the default failure check of functions that only return
err. Other return values are left as declared.

Add a test that builds a DLL wrapping RegOpenKeyExW (DWORD retval),
IsValidCodePage (BOOL retval) and GetHandleInformation (BOOL retval
with err) so their results come back with garbage in the upper half of
the register, and checks that the generated wrappers ignore it.

Fixes golang/go#81249

Change-Id: I1e4cd3aee945cf32c79032745505ed25dd455857
Reviewed-on: https://go-review.googlesource.com/c/sys/+/836325
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
6 files changed
tree: 611bbd0fcd7a13dca9fbd9f16ad002e3f0fcf6c5
  1. cpu/
  2. execabs/
  3. plan9/
  4. unix/
  5. windows/
  6. .gitattributes
  7. .gitignore
  8. codereview.cfg
  9. CONTRIBUTING.md
  10. go.mod
  11. LICENSE
  12. PATENTS
  13. README.md
README.md

sys

Go Reference

This repository holds supplemental Go packages for low-level interactions with the operating system.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://go.dev/doc/contribute.

The git repository is https://go.googlesource.com/sys.

The main issue tracker for the sys repository is located at https://go.dev/issues. Prefix your issue with “x/sys:” in the subject line, so it is easy to find.