diff options
author | Cheng Shao <astrohavoc@gmail.com> | 2022-10-22 17:32:05 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-11 00:26:55 -0500 |
commit | 3f1e164f68aedee576e87f7548592a221896d229 (patch) | |
tree | a7bda8b4cb7807f29194be157a0941962f058e62 | |
parent | 4d36a1d37d826006b9832f1aabea4c9cd5104a3d (diff) | |
download | haskell-3f1e164f68aedee576e87f7548592a221896d229.tar.gz |
rts: use HAVE_GETPID to guard subprocess related logic
We've previously added detection of getpid() in autoconf. This patch
uses HAVE_GETPID to guard some subprocess related logic in the RTS.
This is required for certain targets like wasm32-wasi, where there
isn't a process model at all.
-rw-r--r-- | rts/Hpc.c | 9 | ||||
-rw-r--r-- | rts/Trace.c | 9 | ||||
-rw-r--r-- | rts/eventlog/EventLogWriter.c | 4 |
3 files changed, 20 insertions, 2 deletions
@@ -203,7 +203,9 @@ startupHpc(void) return; } hpc_inited = 1; +#if defined(HAVE_GETPID) hpc_pid = getpid(); +#endif hpc_tixdir = getenv("HPCTIXDIR"); hpc_tixfile = getenv("HPCTIXFILE"); @@ -387,7 +389,12 @@ exitHpc(void) { // Any sub-process from use of fork from inside Haskell will // not clobber the .tix file. - if (hpc_pid == getpid()) { +#if defined(HAVE_GETPID) + bool is_subprocess = hpc_pid != getpid(); +#else + bool is_subprocess = false; +#endif + if (!is_subprocess) { FILE *f = __rts_fopen(tixFilename,"w+"); writeTix(f); } diff --git a/rts/Trace.c b/rts/Trace.c index 30db2a704c..18bb827cc4 100644 --- a/rts/Trace.c +++ b/rts/Trace.c @@ -485,11 +485,14 @@ void traceWallClockTime_(void) { void traceOSProcessInfo_(void) { if (eventlog_enabled) { + +#if defined(HAVE_GETPID) postCapsetEvent(EVENT_OSPROCESS_PID, CAPSET_OSPROCESS_DEFAULT, getpid()); +#endif -#if !defined(mingw32_HOST_OS) +#if !defined(mingw32_HOST_OS) && defined(HAVE_GETPID) /* Windows has no strong concept of process hierarchy, so no getppid(). * In any case, this trace event is mainly useful for tracing programs * that use 'forkProcess' which Windows doesn't support anyway. @@ -605,7 +608,11 @@ void traceTaskCreate_ (Task *task, #endif { EventTaskId taskid = serialisableTaskId(task); +#if !defined(HAVE_GETPID) + EventKernelThreadId tid = 0; +#else EventKernelThreadId tid = kernelThreadId(); +#endif postTaskCreateEvent(taskid, cap->no, tid); } } diff --git a/rts/eventlog/EventLogWriter.c b/rts/eventlog/EventLogWriter.c index daa6dc3c9d..984b2afb5d 100644 --- a/rts/eventlog/EventLogWriter.c +++ b/rts/eventlog/EventLogWriter.c @@ -68,6 +68,9 @@ static char *outputFileName(void) + 10 /* .eventlog */, "initEventLogFileWriter"); +#if !defined(HAVE_GETPID) + sprintf(filename, "%s.eventlog", prog); +#else if (event_log_pid == -1) { // #4512 // Single process sprintf(filename, "%s.eventlog", prog); @@ -82,6 +85,7 @@ static char *outputFileName(void) sprintf(filename, "%s.%" FMT_Word64 ".eventlog", prog, (StgWord64)event_log_pid); } +#endif stgFree(prog); return filename; } |