SchedSetaffinity implements linux syscall sched_setaffinity(2).
(t *kernel.Task, sysno uintptr, args arch.SyscallArguments)
| 505 | |
| 506 | // SchedSetaffinity implements linux syscall sched_setaffinity(2). |
| 507 | func SchedSetaffinity(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { |
| 508 | tid := args[0].Int() |
| 509 | size := args[1].SizeT() |
| 510 | maskAddr := args[2].Pointer() |
| 511 | |
| 512 | var task *kernel.Task |
| 513 | if tid == 0 { |
| 514 | task = t |
| 515 | } else { |
| 516 | task = t.PIDNamespace().TaskWithID(kernel.ThreadID(tid)) |
| 517 | if task == nil { |
| 518 | return 0, nil, linuxerr.ESRCH |
| 519 | } |
| 520 | // Linux requires the caller's EUID to match the target's |
| 521 | // real or effective UID, or CAP_SYS_NICE in the target's user |
| 522 | // namespace. See kernel/sched/syscalls.c:sched_setaffinity(). |
| 523 | creds := t.Credentials() |
| 524 | tcreds := task.Credentials() |
| 525 | if creds.EffectiveKUID != tcreds.EffectiveKUID && |
| 526 | creds.EffectiveKUID != tcreds.RealKUID && |
| 527 | !creds.HasCapabilityIn(linux.CAP_SYS_NICE, tcreds.UserNamespace) { |
| 528 | return 0, nil, linuxerr.EPERM |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | mask := sched.NewCPUSet(t.Kernel().ApplicationCores()) |
| 533 | if size > mask.Size() { |
| 534 | size = mask.Size() |
| 535 | } |
| 536 | if _, err := t.CopyInBytes(maskAddr, mask[:size]); err != nil { |
| 537 | return 0, nil, err |
| 538 | } |
| 539 | return 0, nil, task.SetCPUMask(mask) |
| 540 | } |
| 541 | |
| 542 | // SchedGetaffinity implements linux syscall sched_getaffinity(2). |
| 543 | func SchedGetaffinity(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…