aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--test/sandbox/ptrace.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/test/sandbox/ptrace.go b/test/sandbox/ptrace.go
index 391c8c79..b6e4130e 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}