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

sys: add windows support #1685

Merged
merged 2 commits into from
Feb 17, 2025
Merged

sys: add windows support #1685

merged 2 commits into from
Feb 17, 2025

Conversation

lmb
Copy link
Collaborator

@lmb lmb commented Feb 14, 2025

More Windows pieces. Note that package ebpf, btf, link need follow up work.

efw: add wrappers for eBPF for Windows runtime

Add basic infrastructure to call into the eBPF for Windows runtime. This
uses runtime dynamic linking to call into ebpfapi.dll instead of relying on
CGo. Ultimately this boils down to using syscall.SyscallN to call into
specific functions in the DLL and looks very similar to what we do on Linux.

The most important function is a wrapper for the bpf() function in 
ebpfapi.dll. This is an ABI compatible re-implementation of the Linux bpf()
syscall. Of course, not all of the syscall is implemented yet.

In addition to that there are a variety of helper functions that do not have
a bpf() equivalent and therefore need to be called directly.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

sys: add windows support

The sys package is at the core of the library, so make it work on Windows to
minimise changes to the rest of the code base.

The first important piece is a custom FD abstraction. On Windows, operating
system resources are identified by handles. The differences are large enough
that the efW runtime decided to wrap them in a file descriptor abstraction,
most of which is provided by the Universal C Runtime on Windows. Change our
FD type to call into the efW runtime.

Second, Windows does not have the equivalent of bpffs. Instead objects are
stored in a global table, keyed by a string. This means that we can't use
file system APIs to manipulate pinning.

Third, the bpf() syscall is emulated by calling into ebpfapi.dll. This is
the key piece which allows most code to work unchanged.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>

@lmb lmb force-pushed the windows-sys branch 6 times, most recently from 35ae4b8 to a50a821 Compare February 14, 2025 11:49
@lmb lmb marked this pull request as ready for review February 17, 2025 11:28
@lmb lmb requested review from mmat11 and a team as code owners February 17, 2025 11:28
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.

Thanks! Left a few nits.

@lmb lmb merged commit 8b4b96a into cilium:main Feb 17, 2025
18 checks passed
@lmb lmb deleted the windows-sys branch February 17, 2025 17:22
lmb added 2 commits February 17, 2025 14:46
Add basic infrastructure to call into the eBPF for Windows runtime.
This uses runtime dynamic linking to call into ebpfapi.dll instead
of relying on CGo. Ultimately this boils down to using
syscall.SyscallN to call into specific functions in the DLL and looks
very similar to what we do on Linux.

The most important function is a wrapper for the bpf() function in
ebpfapi.dll. This is an ABI compatible re-implementation of the Linux
bpf() syscall. Of course, not all of the syscall is implemented yet.

In addition to that there are a variety of helper functions that do not
have a bpf() equivalent and therefore need to be called directly.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
The sys package is at the core of the library, so make it work on
Windows to minimise changes to the rest of the code base.

The first important piece is a custom FD abstraction. On Windows,
operating system resources are identified by handles. The differences
are large enough that the efW runtime decided to wrap them in a
file descriptor abstraction, most of which is provided by the
Universal C Runtime on Windows. Change our FD type to call into the efW
runtime.

Second, Windows does not have the equivalent of bpffs. Instead objects
are stored in a global table, keyed by a string. This means that we
can't use file system APIs to manipulate pinning.

Third, the bpf() syscall is emulated by calling into ebpfapi.dll. This
is the key piece which allows most code to work unchanged.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
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