| 1 |
# Windows support |
| 2 |
|
| 3 |
The library has preliminary support for the [eBPF for Windows] runtime, allowing |
| 4 |
you to build Go applications for Windows using the same APIs as on Linux. |
| 5 |
|
| 6 |
!!! warning "Feature parity" |
| 7 |
efW doesn't have feature parity with Linux. Many APIs in |
| 8 |
the library will return `ErrNotSupported` in this case. |
| 9 |
|
| 10 |
!!! warning "Binary compatibility" |
| 11 |
efW is not binary compatible with Linux. It is not possible |
| 12 |
to compile an eBPF program for Linux and use it on Windows. |
| 13 |
|
| 14 |
## Platform specific constants |
| 15 |
|
| 16 |
efW only provides [source compatibility] with Linux. |
| 17 |
While certain Linux map or program types have an equivalent on Windows, they |
| 18 |
don't always behave the same. |
| 19 |
|
| 20 |
For this reason, the various type enumerations have completely distinct values |
| 21 |
on Windows, for example `WindowsHashMap` is the equivalent of `HashMap`. |
| 22 |
Attempting to create a `HashMap` on Windows will return an error, and vice versa. |
| 23 |
|
| 24 |
## Platform specific ELFs |
| 25 |
|
| 26 |
!!! note "" |
| 27 |
Loading Windows ELFs is not supported yet. |
| 28 |
|
| 29 |
ELFs compiled against Linux and Windows headers are not binary compatible. |
| 30 |
Add the following to ELFs targeting Windows until there is an |
| 31 |
[official way to declare the platform](https://github.com/microsoft/ebpf-for-windows/issues/3956): |
| 32 |
|
| 33 |
```C |
| 34 |
const bool __ebpf_for_windows_tag __attribute__((section(".ebpf_for_windows"))) = true; |
| 35 |
``` |
| 36 |
|
| 37 |
## Working with signed programs |
| 38 |
|
| 39 |
The runtime will most likely require all eBPF programs to be signed by |
| 40 |
Microsoft. Signing programs relies on packaging eBPF `.c` files as drivers using |
| 41 |
the [native code pipeline], converting bytecode into a `.sys` file. |
| 42 |
|
| 43 |
The interface to load such drivers does not allow modifying the bytecode or map |
| 44 |
definitions, therefore you can't interact with them via `CollectionSpec`, etc. |
| 45 |
Instead you must load them via `LoadCollection`: |
| 46 |
|
| 47 |
```go |
| 48 |
coll, err := LoadCollection("path\\to\\driver.sys") |
| 49 |
``` |
| 50 |
|
| 51 |
The returned Collection contains Maps and Programs which you can interact with |
| 52 |
as usual. |
| 53 |
|
| 54 |
[eBPF for Windows]: https://github.com/microsoft/ebpf-for-windows |
| 55 |
[source compatibility]: https://github.com/microsoft/ebpf-for-windows?tab=readme-ov-file#2-does-this-provide-app-compatibility-with-ebpf-programs-written-for-linux |
| 56 |
[native code pipeline]: https://github.com/microsoft/ebpf-for-windows/blob/main/docs/NativeCodeGeneration.md |
| 57 |
[LoadCollection]: https://pkg.go.dev/github.com/cilium/ebpf#LoadCollection |