Skip to content

Commit 0b6b2f1

Browse files
authored
Reapply: Port swift specific compiler-rt code to Windows
Reapply: Port swift specific compiler-rt code to Windows
2 parents 9312e0d + 938e300 commit 0b6b2f1

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

compiler-rt/lib/profile/InstrProfilingFile.c

+2-9
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,9 @@ static void exitSignalHandler(int sig) {
367367

368368
static void installExitSignalHandlers(void) {
369369
unsigned I;
370-
struct sigaction sigact;
371-
int err;
372370
for (I = 0; I < lprofCurFilename.NumExitSignals; ++I) {
373-
memset(&sigact, 0, sizeof(sigact));
374-
sigact.sa_handler = exitSignalHandler;
375-
err = sigaction(lprofCurFilename.ExitOnSignals[I], &sigact, NULL);
376-
if (err)
377-
PROF_WARN(
378-
"Unable to install an exit signal handler for %d (errno = %d).\n",
379-
lprofCurFilename.ExitOnSignals[I], err);
371+
lprofInstallSignalHandler(lprofCurFilename.ExitOnSignals[I],
372+
exitSignalHandler);
380373
}
381374
}
382375

compiler-rt/lib/profile/InstrProfilingUtil.c

+19
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <sys/utsname.h>
2525
#endif
2626

27+
#include <signal.h>
2728
#include <stdlib.h>
2829
#include <string.h>
2930

@@ -308,6 +309,24 @@ COMPILER_RT_VISIBILITY const char *lprofFindLastDirSeparator(const char *Path) {
308309
return Sep;
309310
}
310311

312+
COMPILER_RT_VISIBILITY void lprofInstallSignalHandler(int sig,
313+
void (*handler)(int)) {
314+
#ifdef _WIN32
315+
void (*err)(int) = signal(sig, handler);
316+
if (err == SIG_ERR)
317+
PROF_WARN("Unable to install an exit signal handler for %d (errno = %d).\n",
318+
sig, errno);
319+
#else
320+
struct sigaction sigact;
321+
memset(&sigact, 0, sizeof(sigact));
322+
sigact.sa_handler = handler;
323+
int err = sigaction(sig, &sigact, NULL);
324+
if (err)
325+
PROF_WARN("Unable to install an exit signal handler for %d (errno = %d).\n",
326+
sig, err);
327+
#endif
328+
}
329+
311330
COMPILER_RT_VISIBILITY int lprofSuspendSigKill() {
312331
#if defined(__linux__)
313332
int PDeachSig = 0;

compiler-rt/lib/profile/InstrProfilingUtil.h

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ int lprofGetHostName(char *Name, int Len);
6161
unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
6262
void *lprofPtrFetchAdd(void **Mem, long ByteIncr);
6363

64+
void lprofInstallSignalHandler(int sig, void(*handler)(int));
65+
6466
/* Temporarily suspend SIGKILL. Return value of 1 means a restore is needed.
6567
* Other return values mean no restore is needed.
6668
*/

0 commit comments

Comments
 (0)