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

Commit ac64ee6

Browse files
hughbevedantk
authored andcommitted
Port swift specific compiler-rt code to Windows
#5
1 parent b5e8717 commit ac64ee6

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

@@ -219,3 +220,21 @@ COMPILER_RT_VISIBILITY const char *lprofFindLastDirSeparator(const char *Path) {
219220
#endif
220221
return Sep;
221222
}
223+
224+
COMPILER_RT_VISIBILITY void lprofInstallSignalHandler(int sig,
225+
void (*handler)(int)) {
226+
#ifdef _WIN32
227+
void (*err)(int) = signal(sig, handler);
228+
if (err == SIG_ERR)
229+
PROF_WARN("Unable to install an exit signal handler for %d (errno = %d).\n",
230+
sig, errno);
231+
#else
232+
struct sigaction sigact;
233+
memset(&sigact, 0, sizeof(sigact));
234+
sigact.sa_handler = handler;
235+
int err = sigaction(sig, &sigact, NULL);
236+
if (err)
237+
PROF_WARN("Unable to install an exit signal handler for %d (errno = %d).\n",
238+
sig, err);
239+
#endif
240+
}

lib/profile/InstrProfilingUtil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ int lprofGetHostName(char *Name, int Len);
5151
unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);
5252
void *lprofPtrFetchAdd(void **Mem, long ByteIncr);
5353

54+
void lprofInstallSignalHandler(int sig, void(*handler)(int));
55+
5456
#endif /* PROFILE_INSTRPROFILINGUTIL_H */

0 commit comments

Comments
 (0)