39 lines
893 B
Go
39 lines
893 B
Go
//go:build linux
|
|
|
|
package sandbox
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
const signalKill = int(syscall.SIGKILL)
|
|
|
|
func platformSupported() error {
|
|
return nil
|
|
}
|
|
|
|
// attachToCgroup starts nsjail directly inside the run cgroup, so no
|
|
// instruction of nsjail or of the program runs outside its limits, and kills
|
|
// nsjail if the runner dies.
|
|
func attachToCgroup(cmd *exec.Cmd, cgroup *runCgroup) {
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
UseCgroupFD: true,
|
|
CgroupFD: int(cgroup.dir.Fd()),
|
|
Setpgid: true,
|
|
Pdeathsig: syscall.SIGKILL,
|
|
}
|
|
}
|
|
|
|
// peakMemoryKB returns ru_maxrss of nsjail in KiB, the fallback when the
|
|
// kernel has no memory.peak. It overstates small programs because it
|
|
// includes the runner's resident set at exec.
|
|
func peakMemoryKB(state *os.ProcessState) int64 {
|
|
usage, ok := state.SysUsage().(*syscall.Rusage)
|
|
if !ok {
|
|
return 0
|
|
}
|
|
return usage.Maxrss
|
|
}
|