| 1 | /* $Id: winchildren.h 3313 2020-03-16 02:31:38Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * Child process creation and management for kmk.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (c) 2018 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
|---|
| 8 | *
|
|---|
| 9 | * This file is part of kBuild.
|
|---|
| 10 | *
|
|---|
| 11 | * kBuild is free software; you can redistribute it and/or modify
|
|---|
| 12 | * it under the terms of the GNU General Public License as published by
|
|---|
| 13 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 14 | * (at your option) any later version.
|
|---|
| 15 | *
|
|---|
| 16 | * kBuild is distributed in the hope that it will be useful,
|
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | * GNU General Public License for more details.
|
|---|
| 20 | *
|
|---|
| 21 | * You should have received a copy of the GNU General Public License
|
|---|
| 22 | * along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
|---|
| 23 | *
|
|---|
| 24 | */
|
|---|
| 25 |
|
|---|
| 26 | #ifndef INCLUDED_WINCHILDREN_H
|
|---|
| 27 | #define INCLUDED_WINCHILDREN_H
|
|---|
| 28 |
|
|---|
| 29 | /** Child processor group allocator state. */
|
|---|
| 30 | typedef struct MKWINCHILDCPUGROUPALLOCSTATE
|
|---|
| 31 | {
|
|---|
| 32 | /** The group index for the worker allocator.
|
|---|
| 33 | * This is ever increasing and must be modded by g_cProcessorGroups. */
|
|---|
| 34 | unsigned int idxGroup;
|
|---|
| 35 | /** The processor in group index for the worker allocator. */
|
|---|
| 36 | unsigned int idxProcessorInGroup;
|
|---|
| 37 | } MKWINCHILDCPUGROUPALLOCSTATE;
|
|---|
| 38 | /** Pointer to a CPU group allocator state. */
|
|---|
| 39 | typedef MKWINCHILDCPUGROUPALLOCSTATE *PMKWINCHILDCPUGROUPALLOCSTATE;
|
|---|
| 40 |
|
|---|
| 41 | #ifdef DECLARE_HANDLE
|
|---|
| 42 | /**
|
|---|
| 43 | * A childcare worker pipe.
|
|---|
| 44 | */
|
|---|
| 45 | typedef struct WINCCWPIPE
|
|---|
| 46 | {
|
|---|
| 47 | /** My end of the pipe. */
|
|---|
| 48 | HANDLE hPipeMine;
|
|---|
| 49 | /** The child end of the pipe. */
|
|---|
| 50 | HANDLE hPipeChild;
|
|---|
| 51 | /** The event for asynchronous reading. */
|
|---|
| 52 | HANDLE hEvent;
|
|---|
| 53 | /** Which pipe this is (1 == stdout, 2 == stderr). */
|
|---|
| 54 | unsigned char iWhich;
|
|---|
| 55 | /** Set if we've got a read pending already. */
|
|---|
| 56 | BOOL fReadPending;
|
|---|
| 57 | /** Indicator that we've written out something. This is cleared before
|
|---|
| 58 | * we start catching output from a new child and use in the CL.exe
|
|---|
| 59 | * supression heuristics. */
|
|---|
| 60 | BOOL fHaveWrittenOut;
|
|---|
| 61 | /** Number of bytes at the start of the buffer that we've already
|
|---|
| 62 | * written out. We try write out whole lines. */
|
|---|
| 63 | DWORD cbWritten;
|
|---|
| 64 | /** The buffer offset of the read currently pending. */
|
|---|
| 65 | DWORD offPendingRead;
|
|---|
| 66 | /** Read buffer size. */
|
|---|
| 67 | DWORD cbBuffer;
|
|---|
| 68 | /** The read buffer allocation. */
|
|---|
| 69 | unsigned char *pbBuffer;
|
|---|
| 70 | /** Overlapped I/O structure. */
|
|---|
| 71 | OVERLAPPED Overlapped;
|
|---|
| 72 | } WINCCWPIPE;
|
|---|
| 73 | #endif
|
|---|
| 74 |
|
|---|
| 75 | typedef struct WINCCWPIPE *PWINCCWPIPE;
|
|---|
| 76 |
|
|---|
| 77 | void MkWinChildInit(unsigned int cJobSlot);
|
|---|
| 78 | void MkWinChildReExecMake(char **papszArgs, char **papszEnv);
|
|---|
| 79 | intptr_t MkWinChildGetCompleteEventHandle(void);
|
|---|
| 80 | int MkWinChildCreate(char **papszArgs, char **papszEnv, const char *pszShell, struct child *pMkChild, pid_t *pPid);
|
|---|
| 81 | int MkWinChildCreateWithStdOutPipe(char **papszArgs, char **papszEnv, int fdErr, pid_t *pPid, int *pfdReadPipe);
|
|---|
| 82 | void MkWinChildInitCpuGroupAllocator(PMKWINCHILDCPUGROUPALLOCSTATE pState);
|
|---|
| 83 | unsigned int MkWinChildAllocateCpuGroup(PMKWINCHILDCPUGROUPALLOCSTATE pState);
|
|---|
| 84 |
|
|---|
| 85 | #ifdef KMK
|
|---|
| 86 | struct KMKBUILTINENTRY;
|
|---|
| 87 | int MkWinChildCreateBuiltIn(struct KMKBUILTINENTRY const *pBuiltIn, int cArgs, char **papszArgs,
|
|---|
| 88 | char **papszEnv, struct child *pMkChild, pid_t *pPid);
|
|---|
| 89 | int MkWinChildCreateAppend(const char *pszFilename, char **ppszAppend, size_t cbAppend, int fTruncate,
|
|---|
| 90 | struct child *pMkChild, pid_t *pPid);
|
|---|
| 91 |
|
|---|
| 92 | int MkWinChildCreateSubmit(intptr_t hEvent, void *pvSubmitWorker, PWINCCWPIPE pStdOut, PWINCCWPIPE pStdErr,
|
|---|
| 93 | struct child *pMkChild, pid_t *pPid);
|
|---|
| 94 | PWINCCWPIPE MkWinChildcareCreateWorkerPipe(unsigned iWhich, unsigned int idxWorker);
|
|---|
| 95 | void MkWinChildcareWorkerDrainPipes(struct WINCHILD *pChild, PWINCCWPIPE pStdOut, PWINCCWPIPE pStdErr);
|
|---|
| 96 | void MkWinChildcareDeleteWorkerPipe(PWINCCWPIPE pPipe);
|
|---|
| 97 |
|
|---|
| 98 | int MkWinChildCreateRedirect(intptr_t hProcess, pid_t *pPid);
|
|---|
| 99 | # ifdef DECLARE_HANDLE
|
|---|
| 100 | int MkWinChildBuiltInExecChild(void *pvWorker, const char *pszExecutable, char **papszArgs, BOOL fQuotedArgv,
|
|---|
| 101 | char **papszEnvVars, const char *pszCwd, BOOL pafReplace[3], HANDLE pahReplace[3]);
|
|---|
| 102 | # endif
|
|---|
| 103 | #endif /* KMK */
|
|---|
| 104 | int MkWinChildKill(pid_t pid, int iSignal, struct child *pMkChild);
|
|---|
| 105 | int MkWinChildWait(int fBlock, pid_t *pPid, int *piExitCode, int *piSignal, int *pfCoreDumped, struct child **ppMkChild);
|
|---|
| 106 | void MkWinChildExclusiveAcquire(void);
|
|---|
| 107 | void MkWinChildExclusiveRelease(void);
|
|---|
| 108 |
|
|---|
| 109 | #undef CLOSE_ON_EXEC
|
|---|
| 110 | #define CLOSE_ON_EXEC(a_fd) MkWinChildUnrelatedCloseOnExec(a_fd)
|
|---|
| 111 | int MkWinChildUnrelatedCloseOnExec(int fd);
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 | #endif
|
|---|
| 115 |
|
|---|