Skip to content

Commit eb52178

Browse files
committed
[libc][annex_k] Add abort_handler_s.
1 parent b99b05c commit eb52178

File tree

11 files changed

+134
-4
lines changed

11 files changed

+134
-4
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
set(TARGET_ANNEX_K_ENTRYPOINTS "")
1+
set(TARGET_ANNEX_K_ENTRYPOINTS
2+
# stdlib.h entrypoints
3+
libc.src.stdlib.abort_handler_s
4+
)
25

36
set(TARGET_LIBC_ENTRYPOINTS
47
# ctype.h entrypoints

libc/config/linux/riscv/entrypoints.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
set(TARGET_ANNEX_K_ENTRYPOINTS "")
1+
set(TARGET_ANNEX_K_ENTRYPOINTS
2+
# stdlib.h entrypoints
3+
libc.src.stdlib.abort_handler_s
4+
)
25

36
set(TARGET_LIBC_ENTRYPOINTS
47
# ctype.h entrypoints

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
set(TARGET_ANNEX_K_ENTRYPOINTS "")
1+
set(TARGET_ANNEX_K_ENTRYPOINTS
2+
# stdlib.h entrypoints
3+
libc.src.stdlib.abort_handler_s
4+
)
25

36
set(TARGET_LIBC_ENTRYPOINTS
47
# ctype.h entrypoints

libc/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ add_header_macro(
368368
.llvm-libc-types.__search_compare_t
369369
.llvm-libc-types.constraint_handler_t
370370
.llvm-libc-types.div_t
371+
.llvm-libc-types.errno_t
371372
.llvm-libc-types.ldiv_t
372373
.llvm-libc-types.lldiv_t
373374
.llvm-libc-types.locale_t

libc/include/stdlib.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ standards:
55
merge_yaml_files:
66
- stdlib-malloc.yaml
77
macros:
8-
- macro_name: NULL
8+
- macro_name: 'LIBC_HAS_ANNEX_K'
9+
macro_header: annex-k-macros.h
10+
- macro_name: 'NULL'
911
macro_header: null-macro.h
1012
types:
1113
- type_name: __atexithandler_t
@@ -14,6 +16,7 @@ types:
1416
- type_name: __search_compare_t
1517
- type_name: constraint_handler_t
1618
- type_name: div_t
19+
- type_name: errno_t
1720
- type_name: ldiv_t
1821
- type_name: lldiv_t
1922
- type_name: locale_t
@@ -181,6 +184,15 @@ functions:
181184
return_type: int
182185
arguments:
183186
- type: void
187+
- name: abort_handler_s
188+
standards:
189+
- stdc
190+
return_type: void
191+
arguments:
192+
- type: const char *__restrict
193+
- type: void *__restrict
194+
- type: errno_t
195+
guard: 'LIBC_HAS_ANNEX_K'
184196
- name: srand
185197
standards:
186198
- stdc

libc/src/__support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_subdirectory(annex_k)
12
add_subdirectory(CPP)
23
add_subdirectory(macros)
34

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_header_library(
2+
abort_handler_s
3+
HDRS
4+
abort_handler_s.h
5+
DEPENDS
6+
libc.hdr.stdio_macros
7+
libc.hdr.types.errno_t
8+
libc.src.__support.macros.config
9+
libc.src.__support.macros.attributes
10+
libc.src.__support.OSUtil.osutil
11+
libc.src.stdlib.abort
12+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-- Implementation for abort_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___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
10+
#define LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H
11+
12+
#include "hdr/stdio_macros.h"
13+
#include "hdr/types/errno_t.h"
14+
#include "src/__support/OSUtil/io.h"
15+
#include "src/__support/common.h"
16+
#include "src/stdlib/abort.h"
17+
18+
namespace LIBC_NAMESPACE_DECL {
19+
20+
namespace annex_k {
21+
22+
LIBC_INLINE static void abort_handler_s(const char *__restrict msg,
23+
[[maybe_unused]] void *__restrict ptr,
24+
[[maybe_unused]] errno_t error) {
25+
write_to_stderr("abort_handler_s was called in response to a "
26+
"runtime-constraint violation.\n\n");
27+
28+
if (msg)
29+
write_to_stderr(msg);
30+
31+
write_to_stderr(
32+
"\n\nNote to end users: This program was terminated as a result\
33+
of a bug present in the software. Please reach out to your\
34+
software's vendor to get more help.\n");
35+
36+
abort();
37+
}
38+
39+
} // namespace annex_k
40+
41+
} // namespace LIBC_NAMESPACE_DECL
42+
43+
#endif // LLVM_LIBC_SRC___SUPPORT_ANNEX_K_ABORT_HANDLER_S_H

libc/src/stdlib/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,16 @@ add_entrypoint_object(
647647
.${LIBC_TARGET_OS}.abort
648648
)
649649

650+
add_entrypoint_object(
651+
abort_handler_s
652+
SRCS
653+
abort_handler_s.cpp
654+
HDRS
655+
abort_handler_s.h
656+
DEPENDS
657+
libc.src.__support.annex_k.abort_handler_s
658+
)
659+
650660
add_entrypoint_object(
651661
system
652662
ALIAS
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation for abort_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+
#include "src/stdlib/abort_handler_s.h"
10+
#include "src/__support/annex_k/abort_handler_s.h"
11+
12+
namespace LIBC_NAMESPACE_DECL {
13+
14+
LLVM_LIBC_FUNCTION(void, abort_handler_s,
15+
(const char *__restrict msg, void *__restrict ptr,
16+
errno_t error)) {
17+
return annex_k::abort_handler_s(msg, ptr, error);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)