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

Commit 4c9eea1

Browse files
hughbejrose-apple
authored andcommitted
Port swift specific compiler-rt code to Windows (#6)
#5
1 parent d5ac4fa commit 4c9eea1

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

lib/profile/InstrProfilingFile.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,9 @@ static void exitSignalHandler(int sig) {
269269

270270
static void installExitSignalHandlers(void) {
271271
unsigned I;
272-
struct sigaction sigact;
273-
int err;
274272
for (I = 0; I < lprofCurFilename.NumExitSignals; ++I) {
275-
memset(&sigact, 0, sizeof(sigact));
276-
sigact.sa_handler = exitSignalHandler;
277-
err = sigaction(lprofCurFilename.ExitOnSignals[I], &sigact, NULL);
278-
if (err)
279-
PROF_WARN(
280-
"Unable to install an exit signal handler for %d (errno = %d).\n",
281-
lprofCurFilename.ExitOnSignals[I], err);
273+
lprofInstallSignalHandler(lprofCurFilename.ExitOnSignals[I],
274+
exitSignalHandler);
282275
}
283276
}
284277

lib/profile/InstrProfilingUtil.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sys/utsname.h>
2727
#endif
2828

29+
#include <signal.h>
2930
#include <stdlib.h>
3031
#include <string.h>
3132

@@ -245,3 +246,21 @@ COMPILER_RT_VISIBILITY void lprofRestoreSigKill() {
245246
prctl(PR_SET_PDEATHSIG, SIGKILL);
246247
#endif
247248
}
249+
250+
COMPILER_RT_VISIBILITY void lprofInstallSignalHandler(int sig,
251+
void (*handler)(int)) {
252+
#ifdef _WIN32
253+
void (*err)(int) = signal(sig, handler);
254+
if (err == SIG_ERR)
255+
PROF_WARN("Unable to install an exit signal handler for %d (errno = %d).\n",
256+
sig, errno);
257+
#else
258+
struct sigaction sigact;
259+
memset(&sigact, 0, sizeof(sigact));
260+
sigact.sa_handler = handler;
261+
int err = sigaction(sig, &sigact, NULL);
262+
if (err)
263+
PROF_WARN("Unable to install an exit signal handler for %d (errno = %d).\n",
264+
sig, err);
265+
#endif
266+
}

lib/profile/InstrProfilingUtil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ int lprofSuspendSigKill();
5959
/* Restore previously suspended SIGKILL. */
6060
void lprofRestoreSigKill();
6161

62+
void lprofInstallSignalHandler(int sig, void(*handler)(int));
63+
6264
#endif /* PROFILE_INSTRPROFILINGUTIL_H */

0 commit comments

Comments
 (0)