File tree Expand file tree Collapse file tree 11 files changed +89
-3
lines changed Expand file tree Collapse file tree 11 files changed +89
-3
lines changed Original file line number Diff line number Diff line change @@ -228,6 +228,9 @@ set(TARGET_LIBC_ENTRYPOINTS
228
228
# wchar.h entrypoints
229
229
libc.src.wchar.wctob
230
230
231
+ # signal.h entrypoints
232
+ libc.src.signal.raise
233
+
231
234
# gpu/rpc.h entrypoints
232
235
libc.src.gpu.rpc_host_call
233
236
)
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
2
2
libc.include.assert
3
3
libc.include.ctype
4
4
libc.include.string
5
+ libc.include.signal
5
6
libc.include.float
6
7
libc.include.stdint
7
8
libc.include.inttypes
Original file line number Diff line number Diff line change @@ -3,3 +3,9 @@ add_header(
3
3
HDR
4
4
time-macros.h
5
5
)
6
+
7
+ add_header (
8
+ signal_macros
9
+ HDR
10
+ signal-macros.h
11
+ )
Original file line number Diff line number Diff line change
1
+ //===-- Definition of GPU signal number macros ----------------------------===//
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_MACROS_GPU_SIGNAL_MACROS_H
10
+ #define LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H
11
+
12
+ #define SIGINT 2
13
+ #define SIGILL 4
14
+ #define SIGABRT 6
15
+ #define SIGFPE 8
16
+ #define SIGSEGV 11
17
+ #define SIGTERM 15
18
+
19
+ // Max signal number
20
+ #define NSIG 64
21
+
22
+ #define __NSIGSET_WORDS NSIG
23
+
24
+ #endif // LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H
Original file line number Diff line number Diff line change 9
9
#ifndef LLVM_LIBC_MACROS_SIGNAL_MACROS_H
10
10
#define LLVM_LIBC_MACROS_SIGNAL_MACROS_H
11
11
12
- #ifdef __linux__
12
+ #if defined( __linux__ )
13
13
#include "linux/signal-macros.h"
14
+ #elif defined(__NVPTX__ ) || defined(__AMDGPU__ )
15
+ #include "gpu/signal-macros.h"
14
16
#endif
15
17
16
18
#endif // LLVM_LIBC_MACROS_SIGNAL_MACROS_H
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ typedef enum {
38
38
RPC_PRINTF_TO_STDERR_PACKED ,
39
39
RPC_PRINTF_TO_STREAM_PACKED ,
40
40
RPC_REMOVE ,
41
+ RPC_RAISE ,
41
42
RPC_LAST = 0xFFFF ,
42
43
} rpc_opcode_t ;
43
44
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ struct sigaction {
17
17
void (* sa_handler )(int );
18
18
void (* sa_sigaction )(int , siginfo_t * , void * );
19
19
};
20
- sigset_t sa_mask ;
20
+ struct sigset_t sa_mask ;
21
21
int sa_flags ;
22
22
#ifdef __linux__
23
23
// This field is present on linux for most targets.
Original file line number Diff line number Diff line change
1
+ add_entrypoint_object (
2
+ raise
3
+ SRCS
4
+ raise.cpp
5
+ HDRS
6
+ ../raise.h
7
+ DEPENDS
8
+ libc.hdr.types.sigset_t
9
+ libc.src.__support.RPC.rpc_client
10
+ )
11
+
Original file line number Diff line number Diff line change
1
+ // ===-- GPU implementation of signal --------------------------------------===//
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/signal/raise.h"
10
+
11
+ #include " hdr/types/sigset_t.h"
12
+ #include " llvm-libc-types/rpc_opcodes_t.h"
13
+ #include " src/__support/RPC/rpc_client.h"
14
+ #include " src/__support/common.h"
15
+ #include " src/__support/macros/config.h"
16
+
17
+ namespace LIBC_NAMESPACE_DECL {
18
+
19
+ LLVM_LIBC_FUNCTION (int , raise, (int sig)) {
20
+ // We want to first make sure the server is listening before we exit.
21
+ rpc::Client::Port port = rpc::client.open <RPC_RAISE>();
22
+ int ret;
23
+ port.send_and_recv (
24
+ [=](rpc::Buffer *buf) { buf->data [0 ] = static_cast <uint64_t >(sig); },
25
+ [&](rpc::Buffer *buf) { ret = static_cast <int >(buf->data [0 ]); });
26
+ port.close ();
27
+ return ret;
28
+ }
29
+
30
+ } // namespace LIBC_NAMESPACE_DECL
Original file line number Diff line number Diff line change 1
1
add_custom_target (libc_signal_unittests )
2
2
3
- add_libc_unittest (
3
+ add_libc_test (
4
4
raise_test
5
5
SUITE
6
6
libc_signal_unittests
@@ -9,6 +9,7 @@ add_libc_unittest(
9
9
DEPENDS
10
10
libc.include.signal
11
11
libc.src.signal.raise
12
+ UNIT_TEST_ONLY # Requires death tests.
12
13
)
13
14
14
15
add_libc_unittest (
Original file line number Diff line number Diff line change 22
22
#include " src/stdio/gpu/file.h"
23
23
#include < algorithm>
24
24
#include < atomic>
25
+ #include < csignal>
25
26
#include < cstdio>
26
27
#include < cstring>
27
28
#include < memory>
@@ -389,6 +390,12 @@ rpc_status_t handle_server_impl(
389
390
});
390
391
break ;
391
392
}
393
+ case RPC_RAISE: {
394
+ port->recv_and_send ([](rpc::Buffer *buffer) {
395
+ buffer->data [0 ] = raise (static_cast <int >(buffer->data [0 ]));
396
+ });
397
+ break ;
398
+ }
392
399
case RPC_NOOP: {
393
400
port->recv ([](rpc::Buffer *) {});
394
401
break ;
You can’t perform that action at this time.
0 commit comments