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

Function SchedGetaffinity

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

SchedGetaffinity implements linux syscall sched_getaffinity(2).

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

Source from the content-addressed store, hash-verified

541
542// SchedGetaffinity implements linux syscall sched_getaffinity(2).
543func SchedGetaffinity(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
544 tid := args[0].Int()
545 size := args[1].SizeT()
546 maskAddr := args[2].Pointer()
547
548 // This limitation is because linux stores the cpumask
549 // in an array of "unsigned long" so the buffer needs to
550 // be a multiple of the word size.
551 if size&(t.Arch().Width()-1) > 0 {
552 return 0, nil, linuxerr.EINVAL
553 }
554
555 var task *kernel.Task
556 if tid == 0 {
557 task = t
558 } else {
559 task = t.PIDNamespace().TaskWithID(kernel.ThreadID(tid))
560 if task == nil {
561 return 0, nil, linuxerr.ESRCH
562 }
563 }
564
565 mask := task.CPUMask()
566 // The buffer needs to be big enough to hold a cpumask with
567 // all possible cpus.
568 if size < mask.Size() {
569 return 0, nil, linuxerr.EINVAL
570 }
571 _, err := t.CopyOutBytes(maskAddr, mask)
572
573 // NOTE: The syscall interface is slightly different than the glibc
574 // interface. The raw sched_getaffinity syscall returns the number of
575 // bytes used to represent a cpu mask.
576 return uintptr(mask.Size()), nil, err
577}
578
579// Getcpu implements linux syscall getcpu(2).
580func Getcpu(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {

Callers

nothing calls this directly

Calls 11

CPUMaskMethod · 0.95
ThreadIDTypeAlias · 0.92
SizeTMethod · 0.80
TaskWithIDMethod · 0.80
WidthMethod · 0.65
ArchMethod · 0.65
SizeMethod · 0.65
CopyOutBytesMethod · 0.65
IntMethod · 0.45
PointerMethod · 0.45
PIDNamespaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…