-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] implement sigsetjmp/siglongjmp for x86-64 #136072
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
13 commits
Select commit
Hold shift + click to select a range
6dd4406
[libc] implement sigsetjmp/siglongjmp for x86-64
SchrodingerZhu 647b822
Update libc/src/setjmp/siglongjmp.cpp
SchrodingerZhu 11323ef
Merge branch 'main' into libc/sigsetjmp
SchrodingerZhu a612005
address CRs
SchrodingerZhu 1bde1ba
address CRs
SchrodingerZhu 2d9ca38
address CRs
SchrodingerZhu 6496e37
address CRs
SchrodingerZhu abaab76
address CRs
SchrodingerZhu ca31713
address CRs
SchrodingerZhu a88ad07
fix
SchrodingerZhu 80e7dda
remove extra changes
SchrodingerZhu 8fd8ba1
Update libc/hdr/offsetof_macros.h
SchrodingerZhu 0b62f8a
fix
SchrodingerZhu 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//===-- Definition of macros for offsetof ---------------------------------===// | ||
// | ||
// 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_OFFSETOF_MACROS_H | ||
#define LLVM_LIBC_HDR_OFFSETOF_MACROS_H | ||
|
||
#ifdef LIBC_FULL_BUILD | ||
|
||
#include "include/llvm-libc-macros/offsetof-macro.h" | ||
|
||
#else // Overlay mode | ||
|
||
#define __need_offsetof | ||
#include <stddef.h> | ||
|
||
#endif // LLVM_LIBC_FULL_BUILD | ||
|
||
#endif // LLVM_LIBC_HDR_OFFSETOF_MACROS_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
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 |
---|---|---|
@@ -1,3 +1,14 @@ | ||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) | ||
endif() | ||
|
||
add_object_library( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't do this, object libraries are built by default. Entrypoint libraries are only enabled if the corresponding entrypoint is present. This is why every target is now trying to build this and failing if it's not present. |
||
sigsetjmp_epilogue | ||
ALIAS | ||
DEPENDS | ||
.${LIBC_TARGET_OS}.sigsetjmp_epilogue | ||
) | ||
|
||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) | ||
endif() | ||
|
@@ -15,3 +26,20 @@ add_entrypoint_object( | |
DEPENDS | ||
.${LIBC_TARGET_ARCHITECTURE}.longjmp | ||
) | ||
|
||
add_entrypoint_object( | ||
siglongjmp | ||
SRCS | ||
siglongjmp.cpp | ||
HDRS | ||
siglongjmp.h | ||
DEPENDS | ||
.longjmp | ||
) | ||
|
||
add_entrypoint_object( | ||
sigsetjmp | ||
ALIAS | ||
DEPENDS | ||
.${LIBC_TARGET_ARCHITECTURE}.sigsetjmp | ||
) |
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,12 @@ | ||
add_object_library( | ||
sigsetjmp_epilogue | ||
HDRS | ||
../sigsetjmp_epilogue.h | ||
SRCS | ||
sigsetjmp_epilogue.cpp | ||
DEPENDS | ||
libc.src.__support.common | ||
libc.src.__support.OSUtil.osutil | ||
libc.hdr.types.jmp_buf | ||
libc.hdr.types.sigset_t | ||
) |
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,25 @@ | ||
//===-- Implementation of sigsetjmp_epilogue ------------------------------===// | ||
// | ||
// 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/setjmp/sigsetjmp_epilogue.h" | ||
#include "src/__support/OSUtil/syscall.h" | ||
#include "src/__support/common.h" | ||
#include <sys/syscall.h> // For syscall numbers. | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval) { | ||
SchrodingerZhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// If set is NULL, then the signal mask is unchanged (i.e., how is | ||
// ignored), but the current value of the signal mask is nevertheless | ||
// returned in oldset (if it is not NULL). | ||
syscall_impl<long>(SYS_rt_sigprocmask, SIG_SETMASK, | ||
/* set= */ retval ? &buffer->sigmask : nullptr, | ||
/* old_set= */ retval ? nullptr : &buffer->sigmask, | ||
sizeof(sigset_t)); | ||
return retval; | ||
} | ||
} // 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
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,23 @@ | ||
//===-- Implementation of siglongjmp --------------------------------------===// | ||
// | ||
// 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/setjmp/siglongjmp.h" | ||
#include "src/__support/common.h" | ||
#include "src/setjmp/longjmp.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
// siglongjmp is the same as longjmp. The additional recovery work is done in | ||
// the epilogue of the sigsetjmp function. | ||
// TODO: move this inside the TU of longjmp and making it an alias after | ||
// sigsetjmp is implemented for all architectures. | ||
LLVM_LIBC_FUNCTION(void, siglongjmp, (jmp_buf buf, int val)) { | ||
return LIBC_NAMESPACE::longjmp(buf, val); | ||
} | ||
|
||
} // 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,25 @@ | ||
//===-- Implementation header for siglongjmp --------------------*- 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_SETJMP_SIGLONGJMP_H | ||
#define LLVM_LIBC_SRC_SETJMP_SIGLONGJMP_H | ||
|
||
#include "hdr/types/jmp_buf.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
#ifdef LIBC_COMPILER_IS_GCC | ||
[[gnu::nothrow]] | ||
#endif | ||
void siglongjmp(jmp_buf buf, int val); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SETJMP_SIGLONGJMP_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===-- Implementation header for sigsetjmp ---------------------*- 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_SETJMP_SIGSETJMP_H | ||
#define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_H | ||
|
||
#include "hdr/types/jmp_buf.h" | ||
#include "src/__support/macros/config.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
#ifdef LIBC_COMPILER_IS_GCC | ||
[[gnu::nothrow]] | ||
#endif | ||
[[gnu::returns_twice]] int | ||
sigsetjmp(sigjmp_buf buf, int savesigs); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SETJMP_SIGSETJMP_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- Implementation header for sigsetjmp epilogue ------------*- 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_SETJMP_SIGSETJMP_EPILOGUE_H | ||
#define LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_H | ||
|
||
#include "hdr/types/jmp_buf.h" | ||
#include "src/__support/common.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
[[gnu::returns_twice]] int sigsetjmp_epilogue(jmp_buf buffer, int retval); | ||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_SETJMP_SIGSETJMP_EPILOGUE_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
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.
Uh oh!
There was an error while loading. Please reload this page.