Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,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
Expand Down
7 changes: 7 additions & 0 deletions libc/include/stdlib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ functions:
- 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
Expand Down
8 changes: 8 additions & 0 deletions libc/src/__support/annex_k/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ add_header_library(
.abort_handler_s
libc.hdr.types.constraint_handler_t
)

add_header_library(
set_constraint_handler_s
HDRS
set_constraint_handler_s.h
DEPENDS

)
11 changes: 11 additions & 0 deletions libc/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,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
Expand Down
28 changes: 28 additions & 0 deletions libc/src/stdlib/set_constraint_handler_s.cpp
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions libc/src/stdlib/set_constraint_handler_s.h
Original file line number Diff line number Diff line change
@@ -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
Loading