← Writing

eBPF on Windows, the First Year

28 min readSystemsEbpfWindowsVerifierPrevailUbpf
Contents

On a Hyper-V virtual machine running Windows 11 with test signing on, I installed eBPF for Windows v0.5.0, wrote a small BPF program in C, compiled it with clang, and loaded it into the Windows kernel. It counted the socket binds made by each process, from inside the kernel, with no reboot. The same clang that builds BPF for Linux built this; the same libbpf function names loaded it. And when I deleted a NULL check, the program was rejected before it ran, exactly as on Linux, except that the verifier doing the rejecting was not in the kernel at all. It was a user-mode Windows service, and it had proved the program safe by a completely different method.

That port is the subject of this part. Microsoft announced eBPF for Windows in May 2021, and a little over a year later there is a releasable MSI, a verifier, two execution engines, and enough of the libbpf API that a program written for one side has a chance on the other. This is a look at what that first year produced: how a program gets from an ELF file into the Windows kernel, why the verifier moved out of the kernel, what the two ways of running code are and why there are two, and what is still missing next to Linux.

This is Part 7 of a series on eBPF, written for C programmers who know what a process, a system call and a socket are, and nothing about kernel internals. Everything here was run on a Hyper-V Generation-2 VM with eBPF for Windows v0.5.0, the release from the start of this month, compiled with the project’s own clang 11.0.1. The output is pasted from those runs. The note at the end says exactly where and how. The first six parts were about Linux; this one steps sideways to see the same ideas rebuilt on a very different kernel.

Why port eBPF to Windows at all

The pitch for eBPF on Linux, which Part 1 made at length, is that you can hand the kernel a small program, have it proved safe, and run it on an event, with none of the cost of polling, none of the fragility of a kernel module, and none of the wait of a kernel patch. That pitch has nothing Linux-specific in it. Windows has the same three bad options for asking the kernel a question, and the same reasons to want a fourth.

Windows also had, by 2021, a particular reason of its own. A lot of eBPF’s value is in the tools built on it: Cilium for Kubernetes networking, the observability and security agents that watch system calls, the load balancers built on XDP. Those tools were Linux-only because eBPF was Linux-only. If Windows had a compatible runtime, the argument went, that body of work could be made to run on Windows too, without rewriting the BPF programs at the centre of it. Microsoft’s own framing is careful about how much compatibility that means: the stated goal is source-code compatibility for programs that use common hooks and helpers, not binary compatibility and not application compatibility. You should be able to recompile a well-behaved BPF program, not run the Linux .o file unchanged.

There was an early proof that this was not hopeless. In February 2022 the team reported porting Cilium’s layer-4 load balancer to the Windows runtime, and said about 96% of the eBPF code compiled and ran unchanged. That is the kind of number that justifies a project. The eBPF Foundation, which Microsoft helped found in August 2021 under the Linux Foundation, gave the effort a neutral home to coordinate with the kernel community, even though the Windows code itself lives in a Microsoft GitHub repository under the MIT licence.

So the project exists to carry the eBPF programming model, and as much of its ecosystem as will come, onto a kernel that was never built with it in mind. The interesting question is how you do that, because almost nothing about eBPF on Linux is portable as-is. The verifier is kernel C. The JIT is kernel C. The hooks are Linux kernel hooks. The bpf() system call is a Linux system call. Every one of those had to be rebuilt, and the choices made in rebuilding them are what this part is about.

The architecture, and where the verifier went

On Linux, everything happens inside one system call. You call bpf(BPF_PROG_LOAD, …), and inside the kernel the verifier runs, the JIT runs, and the program is installed, all in kernel context. Part 1 followed exactly that call through strace.

Windows cannot do this, and the reason is a design decision that shapes the whole port. The eBPF verifier is a large, complicated piece of code, and the Linux kernel’s own verifier has had a steady stream of bugs, some of them exploitable: errors in its range tracking, and Spectre-style speculative-execution holes where a bounds check is honoured by the hardware architecturally but bypassed speculatively. On Linux that risk is accepted, because the verifier has to be in the kernel for unprivileged loading to mean anything. The Windows project made the opposite call from the start: the announcement in May 2021 already said the verifier would run in a user-mode protected process, not in the kernel. A verifier bug in user mode is a bug in a service, not a hole in the kernel.

That decision splits the load path into pieces that run in three different places. Here they are, one component at a time, as v0.5.0 arranges them.

  • ebpfapi.dll is a user-mode library that exports the libbpf-compatible API — the bpf_object__*, bpf_program__* and bpf_map_* names a Linux programmer already knows. Your program links against it. There is no bpf() system call for it to make; instead it talks over RPC to a service.
  • ebpfsvc.exe is that service, a user-mode service that does the two jobs the Linux kernel does inside BPF_PROG_LOAD: it runs the verifier, and it JIT-compiles the result. Both the verifier and the JIT live here, outside the kernel.
  • ebpfcore.sys is a kernel driver, the execution context. It holds loaded programs and maps and actually runs them. It does not re-verify; it trusts the service’s verdict. It is the only part of this that lives in the kernel’s trust boundary, and it is deliberately the simple part.
  • netebpfext.sys is a second kernel driver that provides the hooks. It registers them through the Windows Filtering Platform (WFP) and the Network Module Registrar (NMR), the standard Windows mechanism by which one driver advertises extension points to another. A networking BPF program attaches to one of netebpfext’s WFP layers.
  • ebpfnetsh.dll is a plugin for netsh, the built-in Windows network shell, so you can load and inspect programs with netsh ebpf … without writing a loader at all. And a port of bpftool ships too, for the inspection commands a Linux user reaches for.

The figure steps through the whole journey from an ELF object to a running program. It is the companion to Part 1’s pipeline figure: same destination, very different route.

From ELF to the bind hook, the Windows way

Loading one program with eBPF for Windows v0.5.0: across a user-mode service and two kernel drivers, with the verifier out of the kernel entirely.

clang · before anything loads

An ordinary BPF ELF object

clang -target bpf -O2 -c bindcount.bpf.c -o bindcount.bpf.o

The same clang BPF backend as on Linux, here version 11.0.1. The object holds BPF bytecode in a section named bind, a map description, and BTF. Nothing Windows-specific is in it yet; the section name is what later decides the program type.

user process · EbpfApi.dll

The loader calls the libbpf-compatible API

bpf_object__open("bindcount.bpf.o");
bpf_object__load(obj);   // or: netsh ebpf add program …

The program is loaded by an ordinary user-mode process linked against EbpfApi.dll, which exports the familiar bpf_object__* and bpf_* names. There is no bpf() system call here; the library talks over RPC to a service.

ebpfsvc · PREVAIL

The verifier runs in user mode

ebpf_rpc_load_program → verify_byte_code()
  → PREVAIL abstract interpretation

The service ebpfsvc.exe runs the PREVAIL verifier on the bytecode before the kernel ever sees it. On Linux the verifier is kernel code; here it is a user-mode service, which is the whole point of the Windows design. A rejection stops here, with no kernel involvement.

ebpfsvc · uBPF

Verified bytecode is JIT-compiled

ubpf_create(); ubpf_load(); ubpf_translate(vm, code, …)
  → x64 machine code

Still in the service, the uBPF JIT turns the verified bytecode into x64. This is the "typical" execution path in 2022. The machine code, not the bytecode, is what the kernel will be handed.

ebpfcore.sys · execution context

The kernel driver accepts the native code

IOCTL → ebpf_core_load_code(code_type = EBPF_CODE_JIT)

ebpfcore.sys is the execution context: it holds programs and maps and runs them. It trusts the service's verdict; it does not re-verify. It only checks that JIT code is allowed at all (see the last stage) before taking it.

netebpfext.sys · WFP

The program is attached to the bind hook

netebpfext.sys → WFP ALE_RESOURCE_ASSIGNMENT layer

netebpfext.sys is a second driver that registers hooks through the Windows Filtering Platform and the Network Module Registrar. A bind program attaches at WFP's resource-assignment layer, so it runs on every socket bind on the machine. netsh ebpf show programs now lists it as mode JIT.

ebpfcore.sys · the HVCI gate

Why native mode exists at all

code_type == EBPF_CODE_JIT blocked by
EBPF_CODE_INTEGRITY_HYPERVISOR_KERNEL_MODE

If Memory Integrity (HVCI) is on, the kernel refuses to accept JIT code: writing fresh executable pages into the kernel is exactly what HVCI forbids. That refusal is the reason for the other path — bpf2c compiling the program to a signed .sys driver ahead of time — which this VM did not need, because its Memory Integrity is off.

Where it runs

  • User modeEbpfApi.dll — your process
  • User-mode serviceebpfsvc.exe — PREVAIL + uBPF
  • Kernelebpfcore.sys + netebpfext.sys
  • Kernel policyHVCI gate on JIT

Green stages run in your own process, teal in the ebpfsvc service (verifier and JIT both), copper in the kernel drivers. On Linux all of this is one bpf() call into the kernel; here the verifier and JIT sit in user mode, and the kernel trusts their output.

The thing to hold onto is the split. On Linux the verifier, the JIT and the execution context are one body of kernel code reached by one syscall. On Windows they are a user-mode service and a kernel driver, talking over RPC, and the kernel driver trusts code it did not itself check. That trust is the price of moving the verifier out of the kernel, and the rest of the port’s design is about making that trust defensible.

Native mode, and why HVCI forces it

There is a second execution path, and it exists because of one specific Windows feature.

Hypervisor-enforced Code Integrity (HVCI), which Windows surfaces as “Memory Integrity” under Core Isolation, uses the hypervisor to guarantee that no page of kernel memory is ever both writable and executable. It is on by default on a lot of modern Windows hardware. A JIT compiler does exactly the thing HVCI forbids: it writes freshly generated machine code into memory and then executes it. So on an HVCI machine, the JIT path cannot work, and ebpfcore.sys knows it. If you hand it JIT code with HVCI on, it refuses, and the refusal is a specific one in the driver’s source:

code_type == EBPF_CODE_JIT blocked by EBPF_CODE_INTEGRITY_HYPERVISOR_KERNEL_MODE

The answer, introduced earlier in 2022 and written up in a Microsoft blog on 25 October, is to not generate code at load time at all. A tool called bpf2c takes the verified BPF bytecode and emits C source, one C statement per BPF instruction, which you then compile with the normal Windows driver toolchain into a .sys driver and sign through the ordinary driver-signing process. The kernel loads that driver the way it loads any signed driver. No pages are generated at run time, so HVCI is satisfied. This is called native mode, and the October blog frames it as the path toward “secure deployments”: a BPF program becomes a signed, auditable artifact built ahead of time, not code conjured in a running service.

You can see what bpf2c produces. Run it on the compiled object from the next section:

> bpf2c --bpf bindcount.bpf.o --sys > bindcount_driver.c

and the generated C has your program as an ordinary function, with the eBPF registers turned into local variables and each instruction turned into a line, tagged with the source line it came from:

count_bind(void* context)
{
    // Prologue
    uint64_t stack[(UBPF_STACK_SIZE + 7) / 8];
    register uint64_t r0 = 0;
    register uint64_t r1 = 0;
    /* … r2 … r6, r10 … */

    r1 = (uintptr_t)context;
    r10 = (uintptr_t)((uint8_t*)stack + sizeof(stack));

    r6 = r1;
    r1 = *(uint64_t*)(uintptr_t)(r6 + OFFSET(16));   // uint64_t pid = ctx->process_id;
    /* … one C statement per BPF instruction … */
}

Alongside the function, bpf2c emits a table of the helpers the program calls, a table of its maps, and a hash of the program’s type information, all wired into a _get_programs() entry point the driver exposes. The whole generated file for this one small program is 428 lines. The verifier has already run inside bpf2c by the time this C exists, so the bytecode baked into the driver is bytecode that passed. In 2022 the JIT path is still described as the typical one and native mode as the addition for HVCI and for signed deployment; both are supported, and which you get is a choice. Everything in this post uses the JIT path, because this VM has Memory Integrity turned off.

The program: counting binds per process

Part 1’s program counted how many times each process called execve(), by hooking the sys_enter_execve tracepoint. The obvious thing to do here is to port it directly. It cannot be done, and the reason is itself a fact about the Windows port: there are no tracepoints. eBPF for Windows in 2022 has networking hooks, built on WFP, and nothing that corresponds to Linux’s tracing hooks — no tracepoints, no kprobes, no execve hook. If you compile the Part 1 program and ask the verifier about it, it does not get as far as checking the code:

> netsh ebpf show verification tp.bpf.o
Program type for section tracepoint/syscalls/sys_enter_execve not found.

> netsh ebpf add program tp.bpf.o
error 131: could not load program

The section name that tells libbpf “this is a tracepoint program” names a program type that does not exist on this platform. So the port of Part 1’s idea is not a port of its program. The nearest thing the Windows hooks support is counting a per-process event that is a network event, and the closest match is the bind hook: it fires every time a process binds a socket to an address, and its context carries the process ID and the binding application’s image path. So instead of “how many times did each process call execve()”, the question becomes “how many times did each process bind() a socket”, which the bind hook can answer exactly the way the tracepoint answered the first one.

Here is the kernel half. It is deliberately the same shape as Part 1’s: look up the process in a hash map, bump a counter if it is there, insert it with a count of 1 if it is not.

// bindcount.bpf.c — runs in the Windows kernel, once per bind()
#include "bpf_helpers.h"

#define NAME_LEN 64

typedef struct
{
    uint64_t count;
    uint8_t name[NAME_LEN]; // the tail of the image path
} entry_t;

SEC("maps")
struct bpf_map_def counts = {
    .type = BPF_MAP_TYPE_HASH,
    .key_size = sizeof(uint64_t),
    .value_size = sizeof(entry_t),
    .max_entries = 1024};

SEC("bind")
bind_action_t
count_bind(bind_md_t* ctx)
{
    uint64_t pid = ctx->process_id;
    entry_t fresh = {0};
    entry_t* entry;

    if (ctx->operation != BIND_OPERATION_BIND)
        return BIND_PERMIT;

    entry = bpf_map_lookup_elem(&counts, &pid);
    if (entry) {
        entry->count++;
        return BIND_PERMIT;
    }

    uint8_t* start = ctx->app_id_start;
    uint8_t* end = ctx->app_id_end;
    if (end - start > NAME_LEN)
        start = end - NAME_LEN;
    for (int i = 0; i < NAME_LEN; i++) {
        if (start + i >= end)
            break;
        fresh.name[i] = start[i];
    }
    fresh.count = 1;
    bpf_map_update_elem(&counts, &pid, &fresh, BPF_NOEXIST);
    return BIND_PERMIT;
}

A reader of Part 1 will recognise almost all of it, but the differences are the interesting part, because every one of them is a place where the Windows port made a choice:

  • The hook is SEC("bind"), not a tracepoint. The program type is BPF_PROG_TYPE_BIND, a Windows-specific type with no Linux equivalent. Its context is a bind_md_t, carrying the process ID, the operation (bind, unbind, or the post-bind notification), the socket address, and a pointer pair app_id_start/app_id_end bounding the binding program’s image path.
  • The return value is a verdict, BIND_PERMIT or BIND_DENY. A bind program is not a passive observer like a tracepoint; it sits in the datapath and can refuse the bind. We permit everything; we are only counting. But the hook’s whole reason to exist is that it can say no, which is why the shipped samples include a port-quota enforcer.
  • The map is a struct bpf_map_def in a section called maps, the older map-definition syntax. Part 1 used the newer BTF-defined .maps form and noted libbpf was deprecating the old one. On Windows in 2022 the old form is what you use: BTF-defined maps are not supported here yet, and the headers still define bpf_map_def.
  • There is no __sync_fetch_and_add. Part 1 incremented the counter atomically, because a tracepoint can fire on several CPUs at once. I wrote this one atomically too, at first, and it would not load: the uBPF engine in v0.5.0 does not implement the atomic add instruction, and the kernel rejected the program with an opaque LMEM error at load time. A plain entry->count++ loads and runs. That is a real gap — on a machine binding sockets on many cores you could lose a count to a race — but it is the gap this release has, and writing around it is the period-correct thing to do.

The build is the same two-step as Linux, with the same clang. The one thing to know is the compiler version: eBPF for Windows in 2022 pins clang 11.0.1, and the docs say clang 12 and later are not yet supported. So you install exactly that, and compile against the headers the project ships:

> clang -target bpf -O2 -c bindcount.bpf.c -o bindcount.bpf.o

No vmlinux.h, because there is no /sys/kernel/btf/vmlinux to generate it from and nothing on Windows to generate it about; the program includes the project’s bpf_helpers.h and the Windows hook definitions instead. Otherwise it is the clang BPF backend you already know, emitting an ordinary BPF ELF object.

Loading it, two ways

The quickest way to load the program is the one that needs no code of your own, netsh:

> netsh ebpf add program bindcount.bpf.o
Loaded with ID 65546

> netsh ebpf show programs

    ID  Pins  Links  Mode       Type           Name
======  ====  =====  =========  =============  ====================
 65546     1      1  JIT        bind           count_bind

The Mode column says JIT: the program was verified by PREVAIL in the service and compiled by uBPF, and ebpfcore.sys is running the resulting x64. The Type is bind, and it is attached, through netebpfext.sys, to WFP’s resource-assignment layer, so it is now running on every socket bind on the machine.

But to read the counts back and print them, the way Part 1’s C tool did, you write the user-space half. It is the same libbpf shape as on Linux — open the object, load it, attach the program, sleep, then walk the map — using the bpf_object__* functions that ebpfapi.dll exports:

// bindcount.c — load, attach, wait, read the map
obj = bpf_object__open("bindcount.bpf.o");
bpf_object__load(obj);                               // verify (in ebpfsvc), JIT, install
prog = bpf_object__find_program_by_name(obj, "count_bind");
link = bpf_program__attach(prog);                    // attach to the bind hook
/* … Sleep(seconds) … */
fd = bpf_object__find_map_fd_by_name(obj, "counts");
while (bpf_map_get_next_key(fd, prev, &next) == 0) {
    bpf_map_lookup_elem(fd, &next, &entry);
    /* print next (the PID), the image name, entry.count */
}

That compiles with the ordinary Windows C compiler against the SDK the project ships, linking EbpfApi.lib. Running it, while a single PowerShell process bound ten UDP sockets:

> bindcount.exe 12
counting bind() for 12 s
  6172  powershell.exe           10

Ten binds, attributed to one process by ID, with the process’s image name read out of the bind context — the same shape of answer as Part 1’s sh 13, obtained the same way, through a hash map that the kernel program writes and user space reads. The difference is entirely underneath: the bpf_object__load call did not make a system call into a kernel verifier. It made an RPC to ebpfsvc, which verified and JIT-compiled the program and handed the result to the kernel driver.

The verifier: PREVAIL, and abstract interpretation

The most interesting difference is the verifier, and the clearest way to see it is to break the program the same way Part 1 did. bpf_map_lookup_elem returns a pointer into the map, or NULL if the key is absent. Part 1 removed the NULL check and watched the Linux verifier reject it. Do the same here — delete the if (entry) and increment whatever the lookup returned:

    entry = bpf_map_lookup_elem(&counts, &pid);
    entry->count++; /* no NULL check */

clang compiles it without complaint; to clang it is valid C. The Windows verifier refuses it:

> netsh ebpf show verification nonull.bpf.o
Verification failed

Verification report:
;     entry->count++; /* no NULL check */
20: Possible null access (valid_access(r0.offset, width=8) for read)
;     entry->count++; /* no NULL check */
22: Possible null access (valid_access(r0.offset, width=8) for write)

2 errors

and loading it fails outright:

> netsh ebpf add program nonull.bpf.o
error 13: could not load program

Put the two verifiers’ rejections of the identical bug side by side. Here is Linux, from Part 1 (kernel 5.15):

13: (db) lock *(u64 *)(r0 +0) += r1
R0 invalid mem access 'map_value_or_null'
processed 13 insns (limit 1000000) ...

and here is Windows:

20: Possible null access (valid_access(r0.offset, width=8) for read)
22: Possible null access (valid_access(r0.offset, width=8) for write)

Both caught it. Both say the register holding the lookup result might be NULL and is being dereferenced without a check. But the words are different because the method is different, and the difference is the whole point.

The Linux verifier walks paths. It explores the control-flow graph, carrying a state for each register — a type, a range, whether it might be NULL — and when a path reaches a dereference of something typed map_value_or_null, it stops with an error. Its diagnostics count instructions processed and states, because walking paths and tracking states is literally what it does. Part 1’s rejection ended “processed 13 insns”; a verifier that walks paths measures itself in paths.

The Windows verifier is PREVAIL, and it does not walk paths. PREVAIL is built on abstract interpretation: instead of exploring concrete paths, it computes, for each point in the program, an abstract invariant — a set of linear constraints that hold over the registers and stack on all paths reaching that point at once. You can ask it to print those invariants. Here is PREVAIL’s state on the correct program, just after the lookup at instruction 19:

19:
  r0 = bpf_map_lookup_elem:1(map_fd r1, map_key r2);
Post-invariant: [
    r0.shared_offset=0, r0.shared_region_size=72, r0.type=shared, r0.value=[0, 2147418112],
    ... ]

Read r0.value=[0, 2147418112]: after the lookup, PREVAIL knows r0 is a pointer into a 72-byte shared region (our map value is 72 bytes), and that its value ranges over an interval that includes zero. Zero is NULL. So at the next instruction, which dereferences r0, the check it applies is valid_access(r0.offset, width=8), and because the interval allows zero, that access is not provably valid. On the correct program, the if (entry) splits the state into two: on the branch where r0 == 0 the program returns, and on the branch where it is non-zero the interval excludes zero and the dereference is safe. Delete the check and there is no split, the interval keeps zero, and the access is a “possible null access”. No paths are walked; the conclusion falls out of the interval arithmetic.

So the two verifiers reach the same verdict about the same bug by opposite routes: one enumerates concrete paths and tracks a NULL-or-not type; the other computes an interval over all paths at once and finds that the interval contains zero. The security property is identical — a program with a possible NULL dereference never runs — and in both cases the program was rejected before it executed a single instruction.

What it can and can’t do, in October 2022

Everything above works, and the list of what works is real: a verifier, two execution engines, the networking hooks, a usable slice of the libbpf API, a bpftool port, a netsh plugin, and enough map support to write useful programs. But the gaps next to Linux are large, and being honest about them is the point of a part dated now rather than later. The figure lays them out; the rest of this section walks the ones that bite.

Linux and eBPF for Windows, October 2022

The same feature on both sides, where each stood at this part's date. Linux here means kernel 6.0; Windows means eBPF for Windows v0.5.0.

FeatureLinux (6.0)Windows (v0.5.0)
Verifierin-kernel path walkPREVAIL, in user mode abstract interpretation
JITin-kernel, per archuBPF, in ebpfsvc
Ahead-of-time native—bpf2c → signed .sys
clang BPF front endany recent11.0.1 only
libbpf-style APIlibbpf96 exports in EbpfApi.dll
bpftoolupstreamport (bpftool v0.1)
General helpers20719
Map types3013
Ring bufferBPF_MAP_TYPE_RINGBUFringbuf (output only)
Tail callsyesyes
Socket-address hookscgroup connect/recv_acceptconnect4/6, recv_accept4/6
Bind / socket hookscgroup, sockopsbind, sock_ops
XDPdriver / genericWFP MAC-frame, XDP_TX
Perf event arrayyesmissing (reads as unspec)
ring_buffer__pollyescallback only
BTF-defined .mapsyesbpf_map_def only
CO-REyesno relocations
Global variables (.data/.bss)yesno
Linux-ABI bpf() syscallnativewrapper, not ABI-compatible
tc / clsactyesno
kprobes / tracepoints / uprobesyesnone
Production-signed binariesn/a (in tree)test-signed only

Teal is on both sides, green is something Windows has that Linux does not (ahead-of-time native compilation), copper is missing on Windows at this date. The shape is clear: the load-and-run core and the networking hooks are there; tracing, CO-RE and the perf event array are not.

No tracing. This is the big one, and we met it already: no tracepoints, no kprobes, no uprobes, nothing like Linux’s tracing hooks. Everything eBPF for Windows can attach to in 2022 is a network event, through WFP: XDP at the MAC-frame layer, bind, the cgroup-style socket-address hooks (connect4/connect6, recv_accept4/recv_accept6), and sock_ops. That is a coherent set for networking and security-at-the-socket, and nothing for the “watch every execve” and “trace this kernel function” use cases that are half of eBPF’s Linux story. (The connect-redirect hook is not here yet either.)

Thirteen map types, and no perf event array. Linux 6.0 has thirty map types; Windows has thirteen — hash, array, their per-CPU variants, maps-of-maps, LRU hashes, an LPM trie, queue, stack, and a ring buffer. Conspicuously missing is BPF_MAP_TYPE_PERF_EVENT_ARRAY, the classic way a BPF program streams per-event records up to user space. Ask the tooling to make one and it does not even recognise the type:

          Map Type  Size   Size  Entries  Name
==================  ====  =====  =======  ========
            unspec     4      4        1  pa

The Cilium port in February had to treat the perf event array as optional for exactly this reason. The ring buffer is present, but only its callback-style ring_buffer__new API — there is no ring_buffer__poll, the synchronous form, yet.

No CO-RE, no BTF-defined maps, no global variables. Part 6 was about compile-once-run-everywhere: BTF, CO-RE relocations, vmlinux.h, skeletons. None of that machinery is here. Maps are defined the old bpf_map_def way; there is no CO-RE and no .data/.bss global variables. The portability story eBPF for Windows tells is a different one — recompile the source against the Windows headers — not binary portability of an object across kernels.

The bpf() wrapper is not Linux’s ABI. There is a bpf() entry point among the exports, but its argument layout is not the Linux bpf() ABI, so a Go or Rust loader that drives the Linux syscall directly will not just work; it has to go through ebpfapi.dll. Of the 118 symbols the DLL exports, 96 are libbpf-style names, which is a lot of surface, but it is a parallel implementation of the API, not the Linux kernel ABI underneath it.

Everything is test-signed. Every eBPF for Windows release, this one included, ships test-signed drivers, and the project has no production-signing pipeline yet — the issue tracking it has been open since June 2021. In practice that means the whole thing only runs on a machine in test-signing mode, which is why this entire post happened inside a VM with Secure Boot off and bcdedit -set TESTSIGNING ON. It is a development and research artifact, not something you deploy to a fleet of production Windows servers in October 2022.

Put together, the shape is clear. The hard, novel parts — a verifier out of the kernel, two execution engines, the HVCI-safe native path, a libbpf-compatible API — exist and work. The breadth that makes eBPF indispensable on Linux — tracing, the full map zoo, CO-RE, the signed-and-shipping story — is mostly ahead. For a project a year and a half from its announcement, having a program I wrote in C counting kernel events on a stock Windows kernel, rejected-when-wrong by a formally specified verifier, is a lot.

What we covered

  • eBPF for Windows carries the Linux programming model — load a verified program, attach it to an event, read results through maps — onto a kernel it was never designed for. The goal is source-code compatibility for programs using common hooks and helpers, not binary compatibility.
  • Its defining decision is that the verifier runs in user mode, in the ebpfsvc service, not in the kernel. The load path runs through ebpfapi.dll (the libbpf-compatible API) to that service (PREVAIL verify, then uBPF JIT) to ebpfcore.sys (which trusts the result and runs it) and netebpfext.sys (which provides the WFP hooks).
  • There are two execution paths: JIT via uBPF, the typical one, and native mode, where bpf2c turns verified bytecode into C and then a signed .sys driver. Native mode exists because HVCI forbids writing executable kernel pages at run time, so the JIT path is refused under Memory Integrity.
  • Part 1’s execve-counting program cannot be ported, because Windows has no tracepoints. The nearest equivalent counts socket binds per process, through the bind hook; it counted ten binds from one process, the same shape of answer as Part 1’s thirteen execs.
  • The verifier, PREVAIL, rejects the same missing-NULL-check bug the Linux verifier does, but by abstract interpretation — computing an interval over all paths at once and finding it contains zero — rather than by walking paths. Same verdict, opposite method.
  • Next to Linux in October 2022, Windows is missing tracing hooks, the perf event array, ring_buffer__poll, CO-RE, BTF-defined maps, global variables, the Linux bpf() ABI, and production-signed binaries. What it has is the hard core: a verifier, two engines, the networking hooks, and a libbpf-shaped API.

A later part returns to the Windows port to see what the next stretch of work changes.

A note on the evidence

What I ran, and where. Every listing is pasted from a real run on a Hyper-V Generation-2 virtual machine (4 vCPU, 8 GB) running a Windows 11 Enterprise evaluation image, Secure Boot off, test signing on, and Memory Integrity (HVCI) off, which is the configuration the project’s own VM-setup docs prescribe. I confirmed inside the guest that test signing was on and that Device Guard reported virtualization-based security and HVCI off before installing anything. eBPF for Windows v0.5.0 was installed from its GitHub release MSI. BPF objects were compiled with the project’s pinned compiler, clang 11.0.1, against the headers of the v0.5.0 SDK; this is the exact compiler version the 2022 docs require, so there is no version difference to note. The user-mode loader was built with the ordinary Windows C compiler against the EbpfApi.lib the release ships. bpftool reported itself as the port’s v0.1 over libbpf v1.0.

What I trimmed. Run-time timestamps are left out, as Part 1 trims its loaded_at lines. The guest’s exact Windows build number is recorded in the lab notes rather than here. Program and map IDs are as printed from one load each. The verifier reports are shown to their meaningful lines: the two “possible null access” errors from the rejection, and the one post-lookup invariant (r0.value=[0, 2147418112], r0.shared_region_size=72) from PREVAIL’s verbose output, which also prints a pre- and post-invariant for every instruction. The generated native C is excerpted; the full file is 428 lines. The bind count is from one run in which a single PowerShell process bound exactly ten UDP sockets.

What I cited rather than ran. The Linux verifier rejection in the comparison is from Part 1’s run on kernel 5.15.0-25, reused here because it is the same bug on the same kind of program. The release dates, the architecture as documented, the hook and map inventories, the helper and export counts, and the compatibility gaps are checked against the project’s source and docs as they stood at the end of October 2022, and against the February 2022 Cilium port write-up for the “96% of the code” figure and the October 2022 blog for native mode. PREVAIL’s design — abstract interpretation over a numerical domain — is from its published description; I ran it, and read its invariants, but did not re-derive the method.

What I’d still change. The bind counter drops the atomic increment because v0.5.0’s uBPF does not implement it; on a busy multi-core machine that loses counts to races, and a release with atomic support would let the program match Part 1’s exactly. I ran only the JIT path, because this VM has Memory Integrity off; a fair test of native mode under HVCI — building the bpf2c output into a signed driver and loading it with Memory Integrity on — is the obvious next experiment, and belongs with the later Windows part.

More