From 389402f955cd040962050f68b404b19e74722722 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Fri, 28 Mar 2025 01:47:24 +0900 Subject: [PATCH] test/sandbox/ptrace: generic filter block type Signed-off-by: Ophestra --- test/sandbox/ptrace.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/sandbox/ptrace.go b/test/sandbox/ptrace.go index 391c8c7..b6e4130 100644 --- a/test/sandbox/ptrace.go +++ b/test/sandbox/ptrace.go @@ -101,12 +101,16 @@ type sockFilter struct { /* Filter block */ k uint32 /* Generic multiuse field */ } -func getFilter(pid, index int) ([]sockFilter, error) { - var buf []sockFilter +func getFilter[T comparable](pid, index int) ([]T, error) { + if s := unsafe.Sizeof(*new(T)); s != 8 { + panic(fmt.Sprintf("invalid filter block size %d", s)) + } + + var buf []T if n, errno := ptrace(PTRACE_SECCOMP_GET_FILTER, pid, index, nil); errno != 0 { return nil, &ptraceError{"PTRACE_SECCOMP_GET_FILTER", errno} } else { - buf = make([]sockFilter, n) + buf = make([]T, n) } if _, errno := ptrace(PTRACE_SECCOMP_GET_FILTER, pid, index, unsafe.Pointer(&buf[0])); errno != 0 { return nil, &ptraceError{"PTRACE_SECCOMP_GET_FILTER", errno}