LLVM 22.0.0git
zOSLibFunctions.cpp
Go to the documentation of this file.
1//===-- zOSLibFunctions.cpp -----------------------------------------------===//
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//===----------------------------------------------------------------------===//
10//
11// This file defines z/OS implementations for common functions.
12//
13//===----------------------------------------------------------------------===//
14
15#ifdef __MVS__
16#include <stdio.h>
17#include <string.h>
18#include <sys/resource.h>
19#include <sys/wait.h>
20
21const char *signalName[] = {
22 /* 0 */ nullptr,
23 /* 1 */ "Hangup", // SIGHUP
24 /* 2 */ "Interrupt", // SIGINT
25 /* 3 */ "Aborted", // SIGABRT
26 /* 4 */ "Illegal instruction", // SIGILL
27 /* 5 */ "Polling event", // SIGPOLL
28 /* 6 */ "Socket data available", // SIGURG
29 /* 7 */ "Stopped (signal)", // SIGSTOP
30 /* 8 */ "Floating point exception", // SIGFPE
31 /* 9 */ "Killed", // SIGKILL
32 /* 10 */ "Bus error", // SIGBUS
33 /* 11 */ "Segmentation fault", // SIGSEGV
34 /* 12 */ "Bad system call", // SIGSYS
35 /* 13 */ "Broken pipe", // SIGPIPE
36 /* 14 */ "Alarm clock", // SIGALRM
37 /* 15 */ "Terminated", // SIGTERM
38 /* 16 */ "User defined signal 1", // SIGUSR1
39 /* 17 */ "User defined signal 2", // SIGUSR2
40 /* 18 */ "Abend", // SIGABND
41 /* 19 */ "Continued", // SIGCONT
42 /* 20 */ "Child exited", // SIGCHLD
43 /* 21 */ "Stopped (tty input)", // SIGTTIN
44 /* 22 */ "Stopped (tty output)", // SIGTTOU
45 /* 23 */ "I/O complete", // SIGIO
46 /* 24 */ "Quit", // SIGQUIT
47 /* 25 */ "Stopped", // SIGTSTP
48 /* 26 */ "Trace/breakpoint trap", // SIGTRAP
49 /* 27 */ "I/O error", // SIGIOERR
50 /* 28 */ "Window changed", // SIGWINCH
51 /* 29 */ "CPU time limit exceeded", // SIGXCPU
52 /* 30 */ "File size limit exceeded", // SIGXFSZ
53 /* 31 */ "Virtual timer expired", // SIGVTALRM
54 /* 32 */ "Profiling timer expired", // SIGPROF
55 /* 33 */ "OMVS subsystem shutdown", // SIGDANGER
56 /* 34 */ "Thread stop", // SIGTHSTOP
57 /* 35 */ "Thread resume", // SIGTHCONT
58 /* 36 */ nullptr, // n/a
59 /* 37 */ "Toggle syscall trace", // SIGTRACE
60 /* 38 */ nullptr, // SIGDCE
61 /* 39 */ "System dump", // SIGDUMP
62};
63
64// z/OS Unix System Services does not have strsignal() support, so the
65// strsignal() function is implemented here.
66char *strsignal(int sig) {
67 if (static_cast<size_t>(sig) < (sizeof(signalName) / sizeof(signalName[0])) &&
68 signalName[sig])
69 return const_cast<char *>(signalName[sig]);
70 static char msg[256];
71 sprintf(msg, "Unknown signal %d", sig);
72 return msg;
73}
74
75// z/OS Unix System Services does not have strnlen() support, so the strnlen()
76// function is implemented here.
77size_t strnlen(const char *S, size_t MaxLen) {
78 const char *PtrToNullChar =
79 static_cast<const char *>(memchr(S, '\0', MaxLen));
80 return PtrToNullChar ? PtrToNullChar - S : MaxLen;
81}
82#endif
char * strsignal(int sig) asm("llvm_zos_strsignal")
size_t strnlen(const char *S, size_t MaxLen) asm("llvm_zos_strnlen")