container/seccomp: alias libseccomp types
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m14s
Test / Hakurei (push) Successful in 3m18s
Test / Hpkg (push) Successful in 4m6s
Test / Sandbox (race detector) (push) Successful in 4m20s
Test / Hakurei (race detector) (push) Successful in 5m2s
Test / Flake checks (push) Successful in 1m29s

This enables tests to refer to these types and check its size.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-11-05 05:04:56 +09:00
parent becaf8b6d7
commit b65aba9446
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
2 changed files with 52 additions and 25 deletions

View File

@ -55,13 +55,12 @@ func (e *LibraryError) Is(err error) bool {
type (
// ScmpSyscall represents a syscall number passed to libseccomp via [NativeRule.Syscall].
ScmpSyscall = C.int
ScmpSyscall C.int
// ScmpErrno represents an errno value passed to libseccomp via [NativeRule.Errno].
ScmpErrno = C.int
)
ScmpErrno C.int
// A NativeRule specifies an arch-specific action taken by seccomp under certain conditions.
type NativeRule struct {
NativeRule struct {
// Syscall is the arch-dependent syscall number to act against.
Syscall ScmpSyscall
// Errno is the errno value to return when the condition is satisfied.
@ -70,6 +69,11 @@ type NativeRule struct {
Arg *ScmpArgCmp
}
// syscallRule is equivalent to [NativeRule].
syscallRule = C.struct_hakurei_syscall_rule
)
// ExportFlag configures filter behaviour that are not implemented as rules.
type ExportFlag = C.hakurei_export_flag
const (
@ -152,7 +156,7 @@ func makeFilter(rules []NativeRule, flags ExportFlag, p *[]byte) error {
res, err := C.hakurei_scmp_make_filter(
&ret, C.uintptr_t(allocateP),
arch, multiarch,
(*C.struct_hakurei_syscall_rule)(unsafe.Pointer(&rules[0])),
(*syscallRule)(unsafe.Pointer(&rules[0])),
C.size_t(len(rules)),
flags,
)
@ -203,13 +207,18 @@ const (
_SCMP_CMP_MAX = C._SCMP_CMP_MAX
)
// ScmpDatum is the equivalent of scmp_datum_t;
// Argument datum
type ScmpDatum uint64
type (
// Argument datum.
scmpDatum = C.scmp_datum_t
// ScmpArgCmp is the equivalent of struct scmp_arg_cmp;
// Argument / Value comparison definition
type ScmpArgCmp struct {
// ScmpDatum is equivalent to scmp_datum_t.
ScmpDatum uint64
// Argument / Value comparison definition.
scmpArgCmp = C.struct_scmp_arg_cmp
// ScmpArgCmp is equivalent to struct scmp_arg_cmp.
ScmpArgCmp struct {
// argument number, starting at 0
Arg C.uint
// the comparison op, e.g. SCMP_CMP_*
@ -217,6 +226,7 @@ type ScmpArgCmp struct {
DatumA, DatumB ScmpDatum
}
)
const (
// PersonaLinux is passed in a [ScmpDatum] for filtering calls to syscall.SYS_PERSONALITY.

View File

@ -1,7 +1,9 @@
package seccomp
import (
"reflect"
"testing"
"unsafe"
"hakurei.app/container/std"
)
@ -20,3 +22,18 @@ func TestSyscallResolveName(t *testing.T) {
})
}
}
func TestRuleSize(t *testing.T) {
assertSize[NativeRule, syscallRule](t)
assertSize[ScmpDatum, scmpDatum](t)
assertSize[ScmpArgCmp, scmpArgCmp](t)
}
// assertSize asserts that native and equivalent are of the same size.
func assertSize[native, equivalent any](t *testing.T) {
got := unsafe.Sizeof(*new(native))
want := unsafe.Sizeof(*new(equivalent))
if got != want {
t.Fatalf("%s: %d, want %d", reflect.TypeFor[native]().Name(), got, want)
}
}