Skip to content

Commit 13af6bb

Browse files
committed
[libc][stdlib][annex_k] Add set_constraint_handler_s.
1 parent c6bdbcd commit 13af6bb

File tree

8 files changed

+78
-0
lines changed

8 files changed

+78
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ if(LLVM_LIBC_FULL_BUILD)
10871087
libc.src.stdlib.exit
10881088
libc.src.stdlib.getenv
10891089
libc.src.stdlib.quick_exit
1090+
libc.src.stdlib.set_constraint_handler_s
10901091

10911092
# signal.h entrypoints
10921093
libc.src.signal.kill

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ if(LLVM_LIBC_FULL_BUILD)
12151215
libc.src.stdlib.exit
12161216
libc.src.stdlib.getenv
12171217
libc.src.stdlib.quick_exit
1218+
libc.src.stdlib.set_constraint_handler_s
12181219

12191220
# signal.h entrypoints
12201221
libc.src.signal.kill

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ if(LLVM_LIBC_FULL_BUILD)
12541254
libc.src.stdlib.exit
12551255
libc.src.stdlib.getenv
12561256
libc.src.stdlib.quick_exit
1257+
libc.src.stdlib.set_constraint_handler_s
12571258

12581259
# signal.h entrypoints
12591260
libc.src.signal.kill

libc/include/stdlib.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,13 @@ functions:
202202
- type: void *__restrict
203203
- type: errno_t
204204
guard: 'LIBC_HAS_ANNEX_K'
205+
- name: set_constraint_handler_s
206+
standards:
207+
- stdc
208+
return_type: constraint_handler_t
209+
arguments:
210+
- type: constraint_handler_t
211+
guard: 'LIBC_HAS_ANNEX_K'
205212
- name: srand
206213
standards:
207214
- stdc

libc/src/__support/annex_k/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ add_header_library(
2828
.abort_handler_s
2929
libc.hdr.types.constraint_handler_t
3030
)
31+
32+
add_header_library(
33+
set_constraint_handler_s
34+
HDRS
35+
set_constraint_handler_s.h
36+
DEPENDS
37+
38+
)

libc/src/stdlib/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,17 @@ add_entrypoint_object(
664664
.${LIBC_TARGET_OS}.system
665665
)
666666

667+
add_entrypoint_object(
668+
set_constraint_handler_s
669+
SRCS
670+
set_constraint_handler_s.cpp
671+
HDRS
672+
set_constraint_handler_s.h
673+
DEPENDS
674+
libc.src.__support.annex_k.abort_handler_s
675+
libc.src.__support.annex_k.libc_constraint_handler
676+
)
677+
667678
add_entrypoint_object(
668679
ignore_handler_s
669680
HDRS
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===-- Implementation of set_constraint_handler_s ------------------------===//
2+
//
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
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "set_constraint_handler_s.h"
10+
#include "src/__support/annex_k/abort_handler_s.h"
11+
#include "src/__support/annex_k/libc_constraint_handler.h"
12+
13+
namespace LIBC_NAMESPACE_DECL {
14+
15+
LLVM_LIBC_FUNCTION(constraint_handler_t, set_constraint_handler_s,
16+
(constraint_handler_t handler)) {
17+
auto previous_handler = annex_k::libc_constraint_handler;
18+
19+
if (!handler) {
20+
annex_k::libc_constraint_handler = &annex_k::abort_handler_s;
21+
} else {
22+
annex_k::libc_constraint_handler = handler;
23+
}
24+
25+
return previous_handler;
26+
}
27+
28+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for set_constraint_handler_s ------*- C++ -*-===//
2+
//
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
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H
10+
#define LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H
11+
12+
#include "hdr/types/constraint_handler_t.h"
13+
#include "src/__support/macros/config.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
constraint_handler_t set_constraint_handler_s(constraint_handler_t handler);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_STDLIB_SET_CONSTRAINT_HANDLER_S_H

0 commit comments

Comments
 (0)