-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Implement getitimer and setitimer, add proxy headers for itimerval #134773
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
46f5b38
[libc] Implement getitimer and setitimer, add proxy headers for itime…
tszhin-swe 02031fb
[libc] Fix header clang formatting
tszhin-swe ce4c93f
[libc] Fix test includes
tszhin-swe 6b7ec28
[libc] Add invalid tests and use ErrnoCheckingTest
tszhin-swe 9892c21
[libc] Add restrict to params in yaml
tszhin-swe 2b707c9
Merge branch 'main' into alarm_feature
tszhin-swe 81719c8
Merge branch 'main' into alarm_feature
tszhin-swe 850a729
Merge branch 'main' into alarm_feature
tszhin-swe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Proxy for struct itimerval ----------------------------------------===// | ||
// | ||
// 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_HDR_TYPES_STRUCT_ITIMERVAL_H | ||
#define LLVM_LIBC_HDR_TYPES_STRUCT_ITIMERVAL_H | ||
|
||
#ifdef LIBC_FULL_BUILD | ||
|
||
#include "include/llvm-libc-types/struct_itimerval.h" | ||
|
||
#else | ||
|
||
#include <sys/time.h> | ||
|
||
#endif // LIBC_FULL_BUILD | ||
|
||
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_ITIMERVAL_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- Definition of struct itimerval ------------------------------------===// | ||
// | ||
// 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_TYPES_STRUCT_ITIMERVAL_H | ||
#define LLVM_LIBC_TYPES_STRUCT_ITIMERVAL_H | ||
|
||
#include "struct_timeval.h" | ||
|
||
struct itimerval { | ||
struct timeval it_interval; /* Interval for periodic timer */ | ||
struct timeval it_value; /* Time until next expiration */ | ||
}; | ||
|
||
#endif // LLVM_LIBC_TYPES_STRUCT_ITIMERVAL_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- Implementation header for getitimer -------------------------------===// | ||
// | ||
// 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_SYS_TIME_GETITIMER_H | ||
#define LLVM_LIBC_SRC_SYS_TIME_GETITIMER_H | ||
|
||
#include "hdr/types/struct_itimerval.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
int getitimer(int which, struct itimerval *curr_value); | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SYS_TIME_GETITIMER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//===-- Implementation file for getitimer ---------------------------------===// | ||
// | ||
// 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/sys/time/getitimer.h" | ||
#include "hdr/types/struct_itimerval.h" | ||
#include "src/__support/OSUtil/syscall.h" | ||
#include "src/__support/common.h" | ||
#include "src/errno/libc_errno.h" | ||
#include <sys/syscall.h> | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(int, getitimer, (int which, struct itimerval *curr_value)) { | ||
long ret = | ||
LIBC_NAMESPACE::syscall_impl<long>(SYS_getitimer, which, curr_value); | ||
// On failure, return -1 and set errno. | ||
if (ret < 0) { | ||
libc_errno = static_cast<int>(-ret); | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//===-- Implementation file for setitimer ---------------------------------===// | ||
// | ||
// 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/sys/time/setitimer.h" | ||
#include "hdr/types/struct_itimerval.h" | ||
#include "src/__support/OSUtil/syscall.h" | ||
#include "src/__support/common.h" | ||
#include "src/errno/libc_errno.h" | ||
#include <sys/syscall.h> | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(int, setitimer, | ||
(int which, const struct itimerval *new_value, | ||
struct itimerval *old_value)) { | ||
long ret = LIBC_NAMESPACE::syscall_impl<long>(SYS_setitimer, which, new_value, | ||
old_value); | ||
// On failure, return -1 and set errno. | ||
if (ret < 0) { | ||
libc_errno = static_cast<int>(-ret); | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===-- Implementation header for setitimer -------------------------------===// | ||
// | ||
// 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_SYS_TIME_SETITIMER_H | ||
#define LLVM_LIBC_SRC_SYS_TIME_SETITIMER_H | ||
|
||
#include "hdr/types/struct_itimerval.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
int setitimer(int which, const struct itimerval *new_value, | ||
struct itimerval *old_value); | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SYS_TIME_SETITIMER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//===-- Unittests for getitimer -------------------------------------------===// | ||
// | ||
// 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 "hdr/types/struct_itimerval.h" | ||
#include "src/sys/time/getitimer.h" | ||
#include "test/UnitTest/ErrnoCheckingTest.h" | ||
#include "test/UnitTest/ErrnoSetterMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; | ||
using LlvmLibcSysTimeGetitimerTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest; | ||
|
||
TEST_F(LlvmLibcSysTimeGetitimerTest, SmokeTest) { | ||
struct itimerval timer; | ||
timer.it_value.tv_sec = -1; | ||
timer.it_value.tv_usec = -1; | ||
timer.it_interval.tv_sec = -1; | ||
timer.it_interval.tv_usec = -1; | ||
|
||
ASSERT_THAT(LIBC_NAMESPACE::getitimer(0, &timer), | ||
returns(EQ(0)).with_errno(EQ(0))); | ||
|
||
ASSERT_TRUE(timer.it_value.tv_sec == 0); | ||
ASSERT_TRUE(timer.it_value.tv_usec == 0); | ||
ASSERT_TRUE(timer.it_interval.tv_sec == 0); | ||
ASSERT_TRUE(timer.it_interval.tv_usec == 0); | ||
} | ||
|
||
TEST_F(LlvmLibcSysTimeGetitimerTest, InvalidRetTest) { | ||
struct itimerval timer; | ||
|
||
// out of range timer type (which) | ||
ASSERT_THAT(LIBC_NAMESPACE::getitimer(99, &timer), | ||
returns(NE(0)).with_errno(NE(0))); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ideally there would be a test where the function succeeds and one where it fails. Could you add a test where the function gives an error?
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.
Added