1 //===-- Implementation of sched_getaffinity -------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/sched/sched_getaffinity.h"
11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12 #include "src/__support/common.h"
13 #include "src/errno/libc_errno.h"
17 #include <sys/syscall.h> // For syscall numbers.
19 namespace LIBC_NAMESPACE
{
21 LLVM_LIBC_FUNCTION(int, sched_getaffinity
,
22 (pid_t tid
, size_t cpuset_size
, cpu_set_t
*mask
)) {
23 int ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_sched_getaffinity
, tid
,
29 if (size_t(ret
) < cpuset_size
) {
30 // This means that only |ret| bytes in |mask| have been set. We will have to
31 // zero out the remaining bytes.
32 auto *mask_bytes
= reinterpret_cast<uint8_t *>(mask
);
33 for (size_t i
= size_t(ret
); i
< cpuset_size
; ++i
)
39 } // namespace LIBC_NAMESPACE