Skip to content

Commit bde5123

Browse files
authored
[libc] Provide 'signal.h' header for the GPU (#101996)
Summary: This header is practically useless, but we provide it mostly for the macros so that applications can compile. I'm only doing this for the `libc++` unittests that want it, and it is part of the C standard technically. I just made an RPC call to do `raise`. Anything more isn't going to work since it'd be way too annoying to make the CPU call into some signal handler the GPU registered.
1 parent d1b2940 commit bde5123

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

libc/config/gpu/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(TARGET_PUBLIC_HEADERS
22
libc.include.assert
33
libc.include.ctype
44
libc.include.string
5+
libc.include.signal
56
libc.include.float
67
libc.include.stdint
78
libc.include.inttypes

libc/include/llvm-libc-macros/gpu/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ add_header(
33
HDR
44
time-macros.h
55
)
6+
7+
add_header(
8+
signal_macros
9+
HDR
10+
signal-macros.h
11+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
#define SIG_DFL ((__sighandler_t)(0))
20+
#define SIG_IGN ((__sighandler_t)(1))
21+
#define SIG_ERR ((__sighandler_t)(-1))
22+
23+
// Max signal number
24+
#define NSIG 64
25+
26+
#define __NSIGSET_WORDS NSIG
27+
28+
#endif // LLVM_LIBC_MACROS_GPU_SIGNAL_MACROS_H

libc/include/llvm-libc-macros/signal-macros.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#ifndef LLVM_LIBC_MACROS_SIGNAL_MACROS_H
1010
#define LLVM_LIBC_MACROS_SIGNAL_MACROS_H
1111

12-
#ifdef __linux__
12+
#if defined(__linux__)
1313
#include "linux/signal-macros.h"
14+
#elif defined(__NVPTX__) || defined(__AMDGPU__)
15+
#include "gpu/signal-macros.h"
1416
#endif
1517

1618
#endif // LLVM_LIBC_MACROS_SIGNAL_MACROS_H

libc/include/llvm-libc-types/struct_sigaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct sigaction {
1717
void (*sa_handler)(int);
1818
void (*sa_sigaction)(int, siginfo_t *, void *);
1919
};
20-
sigset_t sa_mask;
20+
struct sigset_t sa_mask;
2121
int sa_flags;
2222
#ifdef __linux__
2323
// This field is present on linux for most targets.

0 commit comments

Comments
 (0)