SchedGetaffinity implements linux syscall sched_getaffinity(2).
(t *kernel.Task, sysno uintptr, args arch.SyscallArguments)
| 541 | |
| 542 | // SchedGetaffinity implements linux syscall sched_getaffinity(2). |
| 543 | func 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). |
| 580 | func Getcpu(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…