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

ebpf: add Windows support #1710

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ jobs:
run: >
gotestsum --raw-command --ignore-non-json-output-lines --junitfile junit.xml --
go test -short -count 1 -json
./
./asm
./btf
./internal
Expand Down
50 changes: 46 additions & 4 deletions asm/func_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions asm/func_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Code generated by internal/cmd/genwinfunctions.awk; DO NOT EDIT.

package asm

// Code in this file is derived from eBPF for Windows, available under the MIT License.

import (
"github.com/cilium/ebpf/internal/platform"
)

// Built-in functions (Windows).
const (
WindowsFnMapLookupElem = BuiltinFunc(platform.WindowsTag | 1)
WindowsFnMapUpdateElem = BuiltinFunc(platform.WindowsTag | 2)
WindowsFnMapDeleteElem = BuiltinFunc(platform.WindowsTag | 3)
WindowsFnMapLookupAndDeleteElem = BuiltinFunc(platform.WindowsTag | 4)
WindowsFnTailCall = BuiltinFunc(platform.WindowsTag | 5)
WindowsFnGetPrandomU32 = BuiltinFunc(platform.WindowsTag | 6)
WindowsFnKtimeGetBootNs = BuiltinFunc(platform.WindowsTag | 7)
WindowsFnGetSmpProcessorId = BuiltinFunc(platform.WindowsTag | 8)
WindowsFnKtimeGetNs = BuiltinFunc(platform.WindowsTag | 9)
WindowsFnCsumDiff = BuiltinFunc(platform.WindowsTag | 10)
WindowsFnRingbufOutput = BuiltinFunc(platform.WindowsTag | 11)
WindowsFnTracePrintk2 = BuiltinFunc(platform.WindowsTag | 12)
WindowsFnTracePrintk3 = BuiltinFunc(platform.WindowsTag | 13)
WindowsFnTracePrintk4 = BuiltinFunc(platform.WindowsTag | 14)
WindowsFnTracePrintk5 = BuiltinFunc(platform.WindowsTag | 15)
WindowsFnMapPushElem = BuiltinFunc(platform.WindowsTag | 16)
WindowsFnMapPopElem = BuiltinFunc(platform.WindowsTag | 17)
WindowsFnMapPeekElem = BuiltinFunc(platform.WindowsTag | 18)
WindowsFnGetCurrentPidTgid = BuiltinFunc(platform.WindowsTag | 19)
WindowsFnGetCurrentLogonId = BuiltinFunc(platform.WindowsTag | 20)
WindowsFnIsCurrentAdmin = BuiltinFunc(platform.WindowsTag | 21)
WindowsFnMemcpy = BuiltinFunc(platform.WindowsTag | 22)
WindowsFnMemcmp = BuiltinFunc(platform.WindowsTag | 23)
WindowsFnMemset = BuiltinFunc(platform.WindowsTag | 24)
WindowsFnMemmove = BuiltinFunc(platform.WindowsTag | 25)
WindowsFnGetSocketCookie = BuiltinFunc(platform.WindowsTag | 26)
WindowsFnStrncpyS = BuiltinFunc(platform.WindowsTag | 27)
WindowsFnStrncatS = BuiltinFunc(platform.WindowsTag | 28)
WindowsFnStrnlenS = BuiltinFunc(platform.WindowsTag | 29)
WindowsFnKtimeGetBootMs = BuiltinFunc(platform.WindowsTag | 30)
WindowsFnKtimeGetMs = BuiltinFunc(platform.WindowsTag | 31)
)
3 changes: 2 additions & 1 deletion asm/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"strings"

"github.com/cilium/ebpf/internal"
"github.com/cilium/ebpf/internal/platform"
"github.com/cilium/ebpf/internal/sys"
)
Expand Down Expand Up @@ -144,7 +145,7 @@ func (ins Instruction) Marshal(w io.Writer, bo binary.ByteOrder) (uint64, error)
fn := BuiltinFunc(ins.Constant)
plat, value := platform.DecodeConstant(fn)
if plat != platform.Native {
return 0, fmt.Errorf("function %s is not supported on this platform", fn)
return 0, fmt.Errorf("function %s (%s): %w", fn, plat, internal.ErrNotSupportedOnOS)
}
cons = int32(value)
} else if ins.OpCode.Class().IsALU() {
Expand Down
28 changes: 24 additions & 4 deletions attachtype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/cilium/ebpf/internal/kallsyms"
"github.com/cilium/ebpf/internal/kconfig"
"github.com/cilium/ebpf/internal/linux"
"github.com/cilium/ebpf/internal/platform"
"github.com/cilium/ebpf/internal/sys"
)

Expand Down Expand Up @@ -311,8 +312,7 @@ func (cs *CollectionSpec) LoadAndAssign(to interface{}, opts *CollectionOptions)

// Evaluate the loader's objects after all (lazy)loading has taken place.
for n, m := range loader.maps {
switch m.typ {
case ProgramArray:
if m.typ.canStoreProgram() {
// Require all lazy-loaded ProgramArrays to be assigned to the given object.
// The kernel empties a ProgramArray once the last user space reference
// to it closes, which leads to failed tail calls. Combined with the library
Expand Down Expand Up @@ -719,6 +719,10 @@ func resolveKconfig(m *MapSpec) error {
return errors.New("map value is not a Datasec")
}

if platform.IsWindows {
return fmt.Errorf(".kconfig: %w", internal.ErrNotSupportedOnOS)
}

type configInfo struct {
offset uint32
size uint32
Expand Down
Loading
Loading