test/sandbox/ptrace: generic filter block type
Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
660a2898dc
commit
389402f955
@ -101,12 +101,16 @@ type sockFilter struct { /* Filter block */
|
|||||||
k uint32 /* Generic multiuse field */
|
k uint32 /* Generic multiuse field */
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFilter(pid, index int) ([]sockFilter, error) {
|
func getFilter[T comparable](pid, index int) ([]T, error) {
|
||||||
var buf []sockFilter
|
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 {
|
if n, errno := ptrace(PTRACE_SECCOMP_GET_FILTER, pid, index, nil); errno != 0 {
|
||||||
return nil, &ptraceError{"PTRACE_SECCOMP_GET_FILTER", errno}
|
return nil, &ptraceError{"PTRACE_SECCOMP_GET_FILTER", errno}
|
||||||
} else {
|
} else {
|
||||||
buf = make([]sockFilter, n)
|
buf = make([]T, n)
|
||||||
}
|
}
|
||||||
if _, errno := ptrace(PTRACE_SECCOMP_GET_FILTER, pid, index, unsafe.Pointer(&buf[0])); errno != 0 {
|
if _, errno := ptrace(PTRACE_SECCOMP_GET_FILTER, pid, index, unsafe.Pointer(&buf[0])); errno != 0 {
|
||||||
return nil, &ptraceError{"PTRACE_SECCOMP_GET_FILTER", errno}
|
return nil, &ptraceError{"PTRACE_SECCOMP_GET_FILTER", errno}
|
||||||
|
Loading…
Reference in New Issue
Block a user