headers: call per-scrape native functions with SyscallN (#2746)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-16 10:33:18 +02:00
committed by GitHub
parent 4cd3e5411d
commit b1b2888e0f
9 changed files with 148 additions and 12 deletions
+5 -2
View File
@@ -20,6 +20,7 @@ package iphlpapi
import (
"encoding/binary"
"fmt"
"syscall"
"unsafe"
"github.com/prometheus-community/windows_exporter/internal/headers/lazyproc"
@@ -105,7 +106,8 @@ func GetOwnerPIDOfTCPPort(family uint32, tcpPort uint16) (uint32, error) {
func getExtendedTcpTable[T any](ulAf uint32, tableClass uint32) ([]T, error) {
var size uint32
ret, _, _ := procGetExtendedTcpTable.Call(
ret, _, _ := syscall.SyscallN(
procGetExtendedTcpTable.Addr(),
0,
uintptr(unsafe.Pointer(&size)),
0,
@@ -120,7 +122,8 @@ func getExtendedTcpTable[T any](ulAf uint32, tableClass uint32) ([]T, error) {
buf := make([]byte, size)
ret, _, _ = procGetExtendedTcpTable.Call(
ret, _, _ = syscall.SyscallN(
procGetExtendedTcpTable.Addr(),
uintptr(unsafe.Pointer(&buf[0])),
uintptr(unsafe.Pointer(&size)),
0,
@@ -54,3 +54,11 @@ func TestGetOwnerPIDOfTCPPort(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, os.Getpid(), pid)
}
func BenchmarkGetTCPConnectionStates(b *testing.B) {
b.ReportAllocs()
for b.Loop() {
_, _ = iphlpapi.GetTCPConnectionStates(windows.AF_INET)
}
}