Skip to content

Commit bc09758

Browse files
committed
[libc][stdlib][annex_k] Add set_constraint_handler_s.
1 parent 7c91a34 commit bc09758

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ if(LLVM_LIBC_FULL_BUILD)
10831083
libc.src.stdlib.getenv
10841084
libc.src.stdlib.ignore_handler_s
10851085
libc.src.stdlib.quick_exit
1086+
libc.src.stdlib.set_constraint_handler_s
10861087

10871088
# signal.h entrypoints
10881089
libc.src.signal.kill

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ if(LLVM_LIBC_FULL_BUILD)
12111211
libc.src.stdlib.getenv
12121212
libc.src.stdlib.ignore_handler_s
12131213
libc.src.stdlib.quick_exit
1214+
libc.src.stdlib.set_constraint_handler_s
12141215

12151216
# signal.h entrypoints
12161217
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
@@ -1250,6 +1250,7 @@ if(LLVM_LIBC_FULL_BUILD)
12501250
libc.src.stdlib.getenv
12511251
libc.src.stdlib.ignore_handler_s
12521252
libc.src.stdlib.quick_exit
1253+
libc.src.stdlib.set_constraint_handler_s
12531254

12541255
# signal.h entrypoints
12551256
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/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)