Skip to content

Reapply: Port swift specific compiler-rt code to Windows #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2019
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 compiler-rt/lib/profile/InstrProfilingFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,16 +367,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 compiler-rt/lib/profile/InstrProfilingUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <sys/utsname.h>
#endif

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

Expand Down Expand Up @@ -308,6 +309,24 @@ COMPILER_RT_VISIBILITY const char *lprofFindLastDirSeparator(const char *Path) {
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
}

COMPILER_RT_VISIBILITY int lprofSuspendSigKill() {
#if defined(__linux__)
int PDeachSig = 0;
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/profile/InstrProfilingUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ 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));

/* Temporarily suspend SIGKILL. Return value of 1 means a restore is needed.
* Other return values mean no restore is needed.
*/
Expand Down