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 #5

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 1 addition & 9 deletions lib/profile/InstrProfilingFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,8 @@ 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 @@ -219,3 +220,21 @@ COMPILER_RT_VISIBILITY const char *lprofFindLastDirSeparator(const char *Path) {
#endif
return Sep;
}

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 @@ -51,4 +51,6 @@ int lprofGetHostName(char *Name, int Len);
unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
void *lprofPtrFetchAdd(void **Mem, long ByteIncr);

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

#endif /* PROFILE_INSTRPROFILINGUTIL_H */