Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/unix: add Errno wrapper for Windows #1659

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Jan 27, 2025

eBPF for Windows has historically aimed to be source compatible with libbpf API. As part of this, POSIX error codes are found in errno.h are used to indicate errors of all kinds.

eBPF for Windows so far aimed to be source compatible with libbpf. This includes using the same error constants (EINVAL, etc.) as libbpf. It does this using the errno.h header supplied by the Microsoft C runtime. Unfortunately, Windows error codes do not always use the same value as Linux does.

Introduce a dedicated Errno type on Windows which maps errors to the correct constant for the platform. This means that syscall.Errno is not an alias for unix.Errno any more.

@lmb lmb force-pushed the windows-unix-errno-wrapper branch 2 times, most recently from 24c2f86 to a37919d Compare January 27, 2025 15:10
@lmb lmb marked this pull request as ready for review January 27, 2025 15:10
@lmb lmb requested a review from a team as a code owner January 27, 2025 15:10
eBPF for Windows has historically aimed to be source compatible with
libbpf API. As part of this, POSIX error codes are found in errno.h
are used to indicate errors of all kinds.

eBPF for Windows so far aimed to be source compatible with libbpf.
This includes using the same error constants (EINVAL, etc.) as libbpf.
It does this using the errno.h header supplied by the Microsoft
C runtime. Unfortunately, Windows error codes do not always use
the same value as Linux does.

Introduce a dedicated Errno type on Windows which maps errors to
the correct constant for the platform. This means that syscall.Errno
is not an alias for unix.Errno any more.

Signed-off-by: Lorenz Bauer <[email protected]>
@lmb lmb force-pushed the windows-unix-errno-wrapper branch from a37919d to 92ec47c Compare January 27, 2025 15:23
Copy link
Collaborator

@ti-mo ti-mo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one nit.

return false
}

func (e Errno) Temporary() bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using these in other Windows-specific code? I don't think an external caller can get ahold of these methods since this is internal/unix.Errno. Unless we need them to satisfy some interface, I propose we remove them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We expose these indirectly because we wrap original errno from bpf() and friends. It'd be surprising / a footgun if those errors behaved different between platforms, I think.

@lmb lmb merged commit efec6c7 into cilium:main Feb 4, 2025
18 checks passed
@lmb lmb deleted the windows-unix-errno-wrapper branch February 4, 2025 13:55
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