Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Port swift specific compiler-rt code to Windows #6

Merged
merged 1 commit into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions lib/profile/InstrProfilingFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,9 @@ static void exitSignalHandler(int sig) {

static void installExitSignalHandlers(void) {
unsigned I;
struct sigaction sigact;
int err;
for (I = 0; I < lprofCurFilename.NumExitSignals; ++I) {
memset(&sigact, 0, sizeof(sigact));
sigact.sa_handler = exitSignalHandler;
err = sigaction(lprofCurFilename.ExitOnSignals[I], &sigact, NULL);
if (err)
PROF_WARN(
"Unable to install an exit signal handler for %d (errno = %d).\n",
lprofCurFilename.ExitOnSignals[I], err);
lprofInstallSignalHandler(lprofCurFilename.ExitOnSignals[I],
exitSignalHandler);
}
}

Expand Down
19 changes: 19 additions & 0 deletions lib/profile/InstrProfilingUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sys/utsname.h>
#endif

#include <signal.h>
#include <stdlib.h>
#include <string.h>

Expand Down Expand Up @@ -245,3 +246,21 @@ COMPILER_RT_VISIBILITY void lprofRestoreSigKill() {
prctl(PR_SET_PDEATHSIG, SIGKILL);
#endif
}

COMPILER_RT_VISIBILITY void lprofInstallSignalHandler(int sig,
void (*handler)(int)) {
#ifdef _WIN32
void (*err)(int) = signal(sig, handler);
if (err == SIG_ERR)
PROF_WARN("Unable to install an exit signal handler for %d (errno = %d).\n",
sig, errno);
#else
struct sigaction sigact;
memset(&sigact, 0, sizeof(sigact));
sigact.sa_handler = handler;
int err = sigaction(sig, &sigact, NULL);
if (err)
PROF_WARN("Unable to install an exit signal handler for %d (errno = %d).\n",
sig, err);
#endif
}
2 changes: 2 additions & 0 deletions lib/profile/InstrProfilingUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ int lprofSuspendSigKill();
/* Restore previously suspended SIGKILL. */
void lprofRestoreSigKill();

void lprofInstallSignalHandler(int sig, void(*handler)(int));

#endif /* PROFILE_INSTRPROFILINGUTIL_H */