-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc][stdlib][annex_k] Add set_constraint_handler_s. #164093
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
base: users/bassiounix/spr/10-14-_libc_annex_k_add_libc_constraint_handler_macros
Are you sure you want to change the base?
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-libc Author: Muhammad Bassiouni (bassiounix) ChangesRFC https://discourse.llvm.org/t/rfc-bounds-checking-interfaces-for-llvm-libc/87685 Add Full diff: https://github.com/llvm/llvm-project/pull/164093.diff 7 Files Affected:
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index bfff3767e245a..1fd1dabca1018 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -1082,6 +1082,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdlib.getenv
libc.src.stdlib.ignore_handler_s
libc.src.stdlib.quick_exit
+ libc.src.stdlib.set_constraint_handler_s
# signal.h entrypoints
libc.src.signal.kill
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 35916c86ee9ab..5d72ad50a50e0 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -1210,6 +1210,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdlib.getenv
libc.src.stdlib.ignore_handler_s
libc.src.stdlib.quick_exit
+ libc.src.stdlib.set_constraint_handler_s
# signal.h entrypoints
libc.src.signal.kill
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 45e4d266f87b7..ebf17a3056092 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -1249,6 +1249,7 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdlib.getenv
libc.src.stdlib.ignore_handler_s
libc.src.stdlib.quick_exit
+ libc.src.stdlib.set_constraint_handler_s
# signal.h entrypoints
libc.src.signal.kill
diff --git a/libc/include/stdlib.yaml b/libc/include/stdlib.yaml
index aed4728a07552..64ba542748413 100644
--- a/libc/include/stdlib.yaml
+++ b/libc/include/stdlib.yaml
@@ -190,6 +190,22 @@ functions:
return_type: int
arguments:
- type: void
+ - name: abort_handler_s
+ standards:
+ - stdc
+ return_type: void
+ arguments:
+ - type: const char *__restrict
+ - type: void *__restrict
+ - type: errno_t
+ guard: 'LIBC_HAS_ANNEX_K'
+ - name: set_constraint_handler_s
+ standards:
+ - stdc
+ return_type: constraint_handler_t
+ arguments:
+ - type: constraint_handler_t
+ guard: 'LIBC_HAS_ANNEX_K'
- name: srand
standards:
- stdc
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index a70c3d6210210..8a6a2041090bb 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -654,6 +654,17 @@ add_entrypoint_object(
.${LIBC_TARGET_OS}.system
)
+add_entrypoint_object(
+ set_constraint_handler_s
+ SRCS
+ set_constraint_handler_s.cpp
+ HDRS
+ set_constraint_handler_s.h
+ DEPENDS
+ libc.src.__support.annex_k.abort_handler_s
+ libc.src.__support.annex_k.libc_constraint_handler
+)
+
add_entrypoint_object(
ignore_handler_s
HDRS
diff --git a/libc/src/stdlib/set_constraint_handler_s.cpp b/libc/src/stdlib/set_constraint_handler_s.cpp
new file mode 100644
index 0000000000000..d3a16d77e3b0a
--- /dev/null
+++ b/libc/src/stdlib/set_constraint_handler_s.cpp
@@ -0,0 +1,28 @@
+//===-- Implementation of set_constraint_handler_s ------------------------===//
+//
+// 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 "set_constraint_handler_s.h"
+#include "src/__support/annex_k/abort_handler_s.h"
+#include "src/__support/annex_k/libc_constraint_handler.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(constraint_handler_t, set_constraint_handler_s,
+ (constraint_handler_t handler)) {
+ auto previous_handler = annex_k::libc_constraint_handler;
+
+ if (!handler) {
+ annex_k::libc_constraint_handler = &annex_k::abort_handler_s;
+ } else {
+ annex_k::libc_constraint_handler = handler;
+ }
+
+ return previous_handler;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdlib/set_constraint_handler_s.h b/libc/src/stdlib/set_constraint_handler_s.h
new file mode 100644
index 0000000000000..f5c6e01712ef0
--- /dev/null
+++ b/libc/src/stdlib/set_constraint_handler_s.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for set_constraint_handler_s ------*- 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_STDLIB_SET_CONSTRAINT_HANDLER_S_H
+#define LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H
+
+#include "hdr/types/constraint_handler_t.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+constraint_handler_t set_constraint_handler_s(constraint_handler_t handler);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H
|
c65ddbe
to
e0fdacc
Compare
e167fd6
to
b2f54c0
Compare
e0fdacc
to
bc09758
Compare
b2f54c0
to
7c91a34
Compare
RFC https://discourse.llvm.org/t/rfc-bounds-checking-interfaces-for-llvm-libc/87685
Add
set_constraint_handler_s
required by Annex K interface in LLVM libc.