-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[libc] Add implementation of getcpu syscall wrapper #150871
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| //===-- Implementation header for getcpu ------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SRC_SCHED_GETCPU_H | ||
| #define LLVM_LIBC_SRC_SCHED_GETCPU_H | ||
|
|
||
| #include "src/__support/macros/config.h" | ||
| #include <sched.h> | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| int getcpu(unsigned int *cpu, unsigned int *node); | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| #endif // LLVM_LIBC_SRC_SCHED_GETCPU_H | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //===-- Implementation of getcpu ------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/sched/getcpu.h" | ||
|
|
||
| #include "src/__support/OSUtil/syscall.h" // For internal syscall function. | ||
| #include "src/__support/common.h" | ||
| #include "src/__support/libc_errno.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| #include <sched.h> | ||
|
||
| #include <sys/syscall.h> // For syscall numbers. | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| LLVM_LIBC_FUNCTION(int, getcpu, (unsigned int *cpu, unsigned int *node)) { | ||
| int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_getcpu, cpu, node); | ||
|
||
| if (ret < 0) { | ||
| libc_errno = -ret; | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| //===-- Unittests for getcpu ----------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "src/__support/OSUtil/syscall.h" | ||
| #include "src/__support/libc_errno.h" | ||
| #include "src/sched/getcpu.h" | ||
| #include "test/UnitTest/ErrnoSetterMatcher.h" | ||
|
|
||
| #include <sched.h> | ||
|
||
|
|
||
| TEST(LlvmLibcSchedGetCpuTest, SmokeTest) { | ||
|
||
| unsigned int current_cpu; | ||
| unsigned int current_node; | ||
| using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; | ||
| ASSERT_THAT(LIBC_NAMESPACE::getcpu(¤t_cpu, ¤t_node), Succeeds(0)); | ||
| } | ||
|
|
||
| TEST(LlvmLibcSchedGetCpuTest, BadPointer) { | ||
| unsigned int current_cpu; | ||
| unsigned int *current_node = reinterpret_cast<unsigned int *>(-1); | ||
| using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; | ||
| ASSERT_THAT(LIBC_NAMESPACE::getcpu(¤t_cpu, current_node), | ||
| Fails(EFAULT)); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this include is unnecessary