diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-03-28 01:47:24 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-03-28 01:47:24 +0900 |
| commit | 389402f955cd040962050f68b404b19e74722722 (patch) | |
| tree | dd3495a25d89e83e3a9a97daa81c981574f92d3d /test | |
| parent | 660a2898dc0dbfe9963d8f336e04582955b56b8a (diff) | |
test/sandbox/ptrace: generic filter block type
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'test')
| -rw-r--r-- | test/sandbox/ptrace.go | 10 |
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} |
