MCPcopy
hub / github.com/google/gvisor / SchedSetaffinity

Function SchedSetaffinity

pkg/sentry/syscalls/linux/sys_thread.go:507–540  ·  view source on GitHub ↗

SchedSetaffinity implements linux syscall sched_setaffinity(2).

(t *kernel.Task, sysno uintptr, args arch.SyscallArguments)

Source from the content-addressed store, hash-verified

505
506// SchedSetaffinity implements linux syscall sched_setaffinity(2).
507func 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).
543func SchedGetaffinity(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {

Callers

nothing calls this directly

Calls 15

CredentialsMethod · 0.95
SizeMethod · 0.95
SetCPUMaskMethod · 0.95
ThreadIDTypeAlias · 0.92
NewCPUSetFunction · 0.92
SizeTMethod · 0.80
TaskWithIDMethod · 0.80
ApplicationCoresMethod · 0.80
KernelMethod · 0.80
CredentialsMethod · 0.65
CopyInBytesMethod · 0.65
IntMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…