2022-03-23 04:04:08 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2022 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
|
|
|
│ │
|
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2022-03-25 14:11:44 +00:00
|
|
|
#include "libc/assert.h"
|
2022-08-13 20:11:56 +00:00
|
|
|
#include "libc/calls/calls.h"
|
2022-03-23 04:04:08 +00:00
|
|
|
#include "libc/calls/internal.h"
|
2022-03-25 14:11:44 +00:00
|
|
|
#include "libc/calls/sig.internal.h"
|
2022-05-23 22:06:11 +00:00
|
|
|
#include "libc/calls/state.internal.h"
|
2022-08-13 20:11:56 +00:00
|
|
|
#include "libc/calls/struct/siginfo.h"
|
2022-05-23 22:06:11 +00:00
|
|
|
#include "libc/calls/syscall_support-nt.internal.h"
|
2022-03-25 14:11:44 +00:00
|
|
|
#include "libc/dce.h"
|
2022-03-23 04:04:08 +00:00
|
|
|
#include "libc/nt/enum/wait.h"
|
|
|
|
#include "libc/nt/runtime.h"
|
|
|
|
#include "libc/nt/synchronization.h"
|
2022-03-25 14:11:44 +00:00
|
|
|
#include "libc/sysv/consts/sa.h"
|
2022-03-23 04:04:08 +00:00
|
|
|
#include "libc/sysv/consts/sicode.h"
|
|
|
|
#include "libc/sysv/consts/sig.h"
|
|
|
|
|
2023-05-09 08:56:56 +00:00
|
|
|
#ifdef __x86_64__
|
|
|
|
|
2023-07-30 15:55:01 +00:00
|
|
|
static textwindows bool CheckForExitedChildProcess(void) {
|
2022-03-23 04:04:08 +00:00
|
|
|
int pids[64];
|
|
|
|
uint32_t i, n;
|
|
|
|
int64_t handles[64];
|
2023-07-30 15:55:01 +00:00
|
|
|
if (!(n = __sample_pids(pids, handles, true))) return false;
|
2022-03-23 04:04:08 +00:00
|
|
|
i = WaitForMultipleObjects(n, handles, false, 0);
|
2023-07-30 15:55:01 +00:00
|
|
|
if (i == kNtWaitFailed) return false;
|
|
|
|
if (i == kNtWaitTimeout) return false;
|
|
|
|
if ((__sighandrvas[SIGCHLD] >= kSigactionMinRva) &&
|
|
|
|
(__sighandflags[SIGCHLD] & SA_NOCLDWAIT)) {
|
2022-03-25 14:11:44 +00:00
|
|
|
CloseHandle(handles[i]);
|
2022-05-21 01:51:41 +00:00
|
|
|
__releasefd(pids[i]);
|
2023-07-30 15:55:01 +00:00
|
|
|
} else {
|
|
|
|
g_fds.p[pids[i]].zombie = true;
|
2022-03-25 14:11:44 +00:00
|
|
|
}
|
2023-07-30 15:55:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if SIGCHLD should be raised on Windows.
|
|
|
|
* @return true if a signal was raised
|
|
|
|
* @note yoinked by fork-nt.c
|
|
|
|
*/
|
|
|
|
textwindows void _check_sigchld(void) {
|
|
|
|
bool should_signal;
|
2022-06-09 03:01:28 +00:00
|
|
|
__fds_lock();
|
2023-07-30 15:55:01 +00:00
|
|
|
should_signal = CheckForExitedChildProcess();
|
2022-06-09 03:01:28 +00:00
|
|
|
__fds_unlock();
|
2023-07-30 15:55:01 +00:00
|
|
|
if (should_signal) {
|
|
|
|
__sig_add(0, SIGCHLD, CLD_EXITED);
|
|
|
|
}
|
2022-03-23 04:04:08 +00:00
|
|
|
}
|
2023-05-09 08:56:56 +00:00
|
|
|
|
|
|
|
#endif /* __x86_64__ */
|