Files
swift-mirror/stdlib/private/StdlibUnittest/InterceptTraps.cpp
John McCall 50d58b2732 Add a lot of calling-convention annotations to the standard library / runtime.
The general rule here is that something needs to be SWIFT_CC(swift)
if it's just declared in Swift code using _silgen_name, as opposed to
importing something via a header.

Of course, SWIFT_CC(swift) expands to nothing by default for now, and
I haven't made an effort yet to add the indirect-result / context
parameter ABI attributes.  This is just a best-effort first pass.

I also took the opportunity to shift a few files to just implement
their shims header and to demote a few things to be private stdlib
interfaces.
2016-05-04 10:31:23 -07:00

50 lines
1.6 KiB
C++

//===--- InterceptTraps.cpp -----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include "swift/Runtime/Config.h"
static void CrashCatcher(int Sig) {
const char *Msg;
switch (Sig) {
case SIGILL: Msg = "CRASHED: SIGILL\n"; break;
case SIGTRAP: Msg = "CRASHED: SIGTRAP\n"; break;
case SIGABRT: Msg = "CRASHED: SIGABRT\n"; break;
case SIGFPE: Msg = "CRASHED: SIGFPE\n"; break;
case SIGBUS: Msg = "CRASHED: SIGBUS\n"; break;
case SIGSEGV: Msg = "CRASHED: SIGSEGV\n"; break;
case SIGSYS: Msg = "CRASHED: SIGSYS\n"; break;
default: Msg = "CRASHED: SIG????\n"; break;
}
write(STDERR_FILENO, Msg, strlen(Msg));
_exit(0);
}
SWIFT_CC(swift)
extern "C" void swift_stdlib_installTrapInterceptor() {
// Disable buffering on stdout so that everything is printed before crashing.
setbuf(stdout, 0);
signal(SIGILL, CrashCatcher);
signal(SIGTRAP, CrashCatcher);
signal(SIGABRT, CrashCatcher);
signal(SIGFPE, CrashCatcher);
signal(SIGBUS, CrashCatcher);
signal(SIGSEGV, CrashCatcher);
signal(SIGSYS, CrashCatcher);
}