chainlesschain 0.162.181 → 0.162.182
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/scripts/build-windows-sandbox-helper.ps1 +163 -0
- package/src/assets/web-panel/assets/{AIOps-cq0dwbnf.js → AIOps-DzZ5_xoj.js} +1 -1
- package/src/assets/web-panel/assets/{ActionButton-CvcgGl3w.js → ActionButton-DeLXddIg.js} +1 -1
- package/src/assets/web-panel/assets/{Analytics-hM2-jFqg.js → Analytics-rvDCmet1.js} +3 -3
- package/src/assets/web-panel/assets/{AppLayout-B9_Gsd_g.js → AppLayout-Yt6QVDnp.js} +5 -5
- package/src/assets/web-panel/assets/{Artifacts-B7bu52Og.js → Artifacts-BS112K5L.js} +1 -1
- package/src/assets/web-panel/assets/{Audit-DThfDgqB.js → Audit-0wJuQrNu.js} +1 -1
- package/src/assets/web-panel/assets/{BackgroundAgents-DjlFiD4v.js → BackgroundAgents-B90PMgbn.js} +1 -1
- package/src/assets/web-panel/assets/{Backup-CK9xJKnG.js → Backup-TkgMglQQ.js} +1 -1
- package/src/assets/web-panel/assets/{BaseInput-DEiSU8K8.js → BaseInput-CQVS9p1l.js} +1 -1
- package/src/assets/web-panel/assets/{Chat-CpT96czj.js → Chat-YTjQHoC7.js} +5 -5
- package/src/assets/web-panel/assets/{ChatBubbleRenderer-BKPPNmZI.js → ChatBubbleRenderer-PR074hUN.js} +1 -1
- package/src/assets/web-panel/assets/{Checkbox-C1GfDnO0.js → Checkbox-5bwaOabq.js} +1 -1
- package/src/assets/web-panel/assets/{Codegen-3DAKgiLx.js → Codegen-BFmNQ_Xe.js} +1 -1
- package/src/assets/web-panel/assets/{Col-74cOwZU1.js → Col-BT_u4Dzp.js} +1 -1
- package/src/assets/web-panel/assets/{Community-tn9Kkz9j.js → Community-CJP52u5b.js} +1 -1
- package/src/assets/web-panel/assets/{Compact-BcoXH7m4.js → Compact-BpzhJE9i.js} +1 -1
- package/src/assets/web-panel/assets/{Compliance-DIPGUBgi.js → Compliance-Cg7rfslp.js} +1 -1
- package/src/assets/web-panel/assets/{Cowork-doD5_91c.js → Cowork-JisxL6Yy.js} +3 -3
- package/src/assets/web-panel/assets/{Cron-C-IDvubz.js → Cron-Bu7Ug_MC.js} +2 -2
- package/src/assets/web-panel/assets/{Crosschain-CdcCoBdj.js → Crosschain-CvuqoLdj.js} +1 -1
- package/src/assets/web-panel/assets/{DID-DdH5aMMA.js → DID-C2u9G8Pu.js} +2 -2
- package/src/assets/web-panel/assets/{Dashboard-DHLA4mm0.js → Dashboard-BFt5Yv3d.js} +2 -2
- package/src/assets/web-panel/assets/{Dropdown-dEeCt7Md.js → Dropdown-DIaT9Wxq.js} +1 -1
- package/src/assets/web-panel/assets/{EmailListRenderer-BMaecFv9.js → EmailListRenderer-D_A601Y4.js} +1 -1
- package/src/assets/web-panel/assets/{FamilyGuardDashboard-DUaUukTN.js → FamilyGuardDashboard--IyQ8I8w.js} +1 -1
- package/src/assets/web-panel/assets/{Federation-CMBE0_rp.js → Federation-BihWHxuY.js} +1 -1
- package/src/assets/web-panel/assets/{FormItemContext-PG-JDbXq.js → FormItemContext-BB8dOXc_.js} +1 -1
- package/src/assets/web-panel/assets/{GenericCardRenderer-Bcb0p88m.js → GenericCardRenderer-DQYhj1HH.js} +1 -1
- package/src/assets/web-panel/assets/{Git-Bgv15myB.js → Git-B-2QZxGf.js} +2 -2
- package/src/assets/web-panel/assets/{Governance-DB8YTArI.js → Governance-CusSb-nG.js} +1 -1
- package/src/assets/web-panel/assets/{Inference-BQMwCWaS.js → Inference-BAjmvPPL.js} +1 -1
- package/src/assets/web-panel/assets/{KnowledgeGraph-B1_ZziiB.js → KnowledgeGraph-DoNYWKYq.js} +1 -1
- package/src/assets/web-panel/assets/{Logs-DovEEnt_.js → Logs-B8fKWD-n.js} +2 -2
- package/src/assets/web-panel/assets/{MarkdownRenderer-D201OL4T.js → MarkdownRenderer-BlJm1J7E.js} +1 -1
- package/src/assets/web-panel/assets/{Marketplace-BlCXSpyB.js → Marketplace-CyOscbSL.js} +1 -1
- package/src/assets/web-panel/assets/{McpTools-CsCR09Wj.js → McpTools-Ex6Om5da.js} +5 -5
- package/src/assets/web-panel/assets/{Memory-CBVRLKno.js → Memory-CDcD8l8r.js} +2 -2
- package/src/assets/web-panel/assets/{MobileBridge-C9OIafgA.js → MobileBridge-xfBqoFDg.js} +1 -1
- package/src/assets/web-panel/assets/{MobileProjects-D_zoJ8Xs.js → MobileProjects-BwObMMA2.js} +1 -1
- package/src/assets/web-panel/assets/{Mtc-vE-HdvLj.js → Mtc-CIWd36OV.js} +5 -5
- package/src/assets/web-panel/assets/{MtcAudit-CPLaekCd.js → MtcAudit-CPX0ouuA.js} +4 -4
- package/src/assets/web-panel/assets/{Multisig-C_UP9C2o.js → Multisig-BDJsIUuW.js} +3 -3
- package/src/assets/web-panel/assets/{NLProgramming-2nODJcU1.js → NLProgramming-DEkbuD3N.js} +1 -1
- package/src/assets/web-panel/assets/{Notes-BhE-SJGu.js → Notes-DJpHRhH1.js} +3 -3
- package/src/assets/web-panel/assets/{NotificationSettings-D21q7BNU.js → NotificationSettings-C1UZ-Qd5.js} +1 -1
- package/src/assets/web-panel/assets/{OrderTableRenderer-0b62GYOD.js → OrderTableRenderer-GlJtqLjT.js} +1 -1
- package/src/assets/web-panel/assets/{Organization-CEqmw_sb.js → Organization-Bbhj0fac.js} +4 -4
- package/src/assets/web-panel/assets/{Overflow-MW-gMDO_.js → Overflow-1H04x3kx.js} +1 -1
- package/src/assets/web-panel/assets/{P2P-CY0hjI_G.js → P2P-CDpPe3et.js} +2 -2
- package/src/assets/web-panel/assets/{PdhVaultBrowser-BbWh7Man.js → PdhVaultBrowser-MUX0Bpvw.js} +3 -3
- package/src/assets/web-panel/assets/{Permissions-ChqEA_4Q.js → Permissions-A07-0Ci1.js} +4 -4
- package/src/assets/web-panel/assets/{PersonalDataHub-B3YrbYfD.js → PersonalDataHub-DhhDWxAZ.js} +5 -5
- package/src/assets/web-panel/assets/{Pipeline-B8WBhhlW.js → Pipeline-CyfbJfe-.js} +1 -1
- package/src/assets/web-panel/assets/{Privacy-Cmb0PXNx.js → Privacy-CNFps3ED.js} +1 -1
- package/src/assets/web-panel/assets/{ProjectInit-hF6zW3Nz.js → ProjectInit--T-u3Dr5.js} +2 -2
- package/src/assets/web-panel/assets/{ProjectSettings-BFSVfpW0.js → ProjectSettings-DJmrK2fC.js} +2 -2
- package/src/assets/web-panel/assets/{Projects-DAWkVFkc.js → Projects-Qx_MdX9k.js} +1 -1
- package/src/assets/web-panel/assets/{Providers-B8yux8Dx.js → Providers-DLzzbOZd.js} +1 -1
- package/src/assets/web-panel/assets/{QrScannerModal-N76cQluO.js → QrScannerModal-CexOomKS.js} +1 -1
- package/src/assets/web-panel/assets/{QuickAsk-ClvZ0KYR.js → QuickAsk-QklGi19_.js} +1 -1
- package/src/assets/web-panel/assets/{Recommend-B-GfgBpT.js → Recommend-Bb9kwSw8.js} +1 -1
- package/src/assets/web-panel/assets/{RemoteSession-mlglCdQi.js → RemoteSession-DZuVNNN5.js} +2 -2
- package/src/assets/web-panel/assets/{Reputation-DJIZzQeG.js → Reputation-Dr5cLP0N.js} +1 -1
- package/src/assets/web-panel/assets/{Row-COzxu_bb.js → Row-oCQHYv5t.js} +1 -1
- package/src/assets/web-panel/assets/{RssFeed-CoYsJQuE.js → RssFeed-IFDEykIR.js} +3 -3
- package/src/assets/web-panel/assets/{Search-DC77Mq9S.js → Search-CspVIxDc.js} +1 -1
- package/src/assets/web-panel/assets/{Security-Loy2EdMO.js → Security-Bm66o_DH.js} +3 -3
- package/src/assets/web-panel/assets/{Services-GUD07Eu0.js → Services-DvanNqXl.js} +2 -2
- package/src/assets/web-panel/assets/{Skeleton-DWzkptYU.js → Skeleton-CHjEe9_O.js} +1 -1
- package/src/assets/web-panel/assets/{Skills-CEDn1r-Z.js → Skills-Cb8jWjMX.js} +1 -1
- package/src/assets/web-panel/assets/{Sla-ub_k4pXh.js → Sla-DxZm1491.js} +1 -1
- package/src/assets/web-panel/assets/{SpeechSettings-D7HLX9CA.js → SpeechSettings-DWxEEclC.js} +1 -1
- package/src/assets/web-panel/assets/{SyncSettings-DbwOvl6m.js → SyncSettings-FIvOFw5p.js} +2 -2
- package/src/assets/web-panel/assets/{Tasks-CBQzoAu5.js → Tasks-CyuLnDFR.js} +1 -1
- package/src/assets/web-panel/assets/{Templates-BNVeIhud.js → Templates-CaNjzV_t.js} +1 -1
- package/src/assets/web-panel/assets/{Tenant-PS9AzhXU.js → Tenant-DjlP6TmH.js} +1 -1
- package/src/assets/web-panel/assets/Terminal-DwzGMniO.js +3 -0
- package/src/assets/web-panel/assets/{TimelineRenderer-CrmXMOkg.js → TimelineRenderer-DoZ8y7y8.js} +1 -1
- package/src/assets/web-panel/assets/{Tokens-DD-VDHw1.js → Tokens-390cg2TC.js} +1 -1
- package/src/assets/web-panel/assets/{Trigger-BsoN_n-n.js → Trigger-CLrtCj5_.js} +1 -1
- package/src/assets/web-panel/assets/{Trust-n8LmN4ZV.js → Trust-DpESfSPn.js} +1 -1
- package/src/assets/web-panel/assets/{UkeySign-C9_7MImA.js → UkeySign-CN6279O0.js} +1 -1
- package/src/assets/web-panel/assets/{VideoEditing-DyBteNgn.js → VideoEditing-DPtAUlSe.js} +1 -1
- package/src/assets/web-panel/assets/{Wallet-BS5ixeXI.js → Wallet-nKOMV_1n.js} +4 -4
- package/src/assets/web-panel/assets/{WebAuthn-spc4UImU.js → WebAuthn-HuXlSOc4.js} +5 -5
- package/src/assets/web-panel/assets/{WorkflowEditor-D7iVvaBO.js → WorkflowEditor-CUfFjARi.js} +1 -1
- package/src/assets/web-panel/assets/{chat-6CmBkHrL.js → chat-6Eq0PcZJ.js} +1 -1
- package/src/assets/web-panel/assets/{colors-BGoCLkxI.js → colors-BP_Sf6Iy.js} +1 -1
- package/src/assets/web-panel/assets/{compact-item-fYZBetMO.js → compact-item-BufMKIh5.js} +1 -1
- package/src/assets/web-panel/assets/{createContext-BeM-1UVj.js → createContext-BBMXxWSW.js} +1 -1
- package/src/assets/web-panel/assets/devWarning-DgVKduH2.js +1 -0
- package/src/assets/web-panel/assets/{hasIn-CE7ZuEnV.js → hasIn-fUK_tRO2.js} +1 -1
- package/src/assets/web-panel/assets/{index-QIpnpZgz.js → index-2A5ph8b2.js} +1 -1
- package/src/assets/web-panel/assets/{index-BU_2qiDk.js → index-3FuwBewR.js} +1 -1
- package/src/assets/web-panel/assets/{index--lap6cf7.js → index-6GmBa4Kg.js} +1 -1
- package/src/assets/web-panel/assets/{index-De0quFDw.js → index-B2vS66eI.js} +1 -1
- package/src/assets/web-panel/assets/{index-D1r9tT3J.js → index-B7Etk0Te.js} +1 -1
- package/src/assets/web-panel/assets/{index-YjcumOZ4.js → index-B9WYSn4m.js} +1 -1
- package/src/assets/web-panel/assets/{index-MtOuq2i6.js → index-BHy6yNiF.js} +1 -1
- package/src/assets/web-panel/assets/{index-RMZ8a7Yt.js → index-BMLHv389.js} +1 -1
- package/src/assets/web-panel/assets/{index-C0v6YKKO.js → index-BWKoBU8R.js} +1 -1
- package/src/assets/web-panel/assets/{index-CRnUE8Cb.js → index-Bkg4ZePE.js} +1 -1
- package/src/assets/web-panel/assets/{index-BsMfoaeo.js → index-C44atv4k.js} +1 -1
- package/src/assets/web-panel/assets/{index-DoXk5KJ8.js → index-CE2DdTP2.js} +1 -1
- package/src/assets/web-panel/assets/{index-B4wiTEOM.js → index-CGjmILDm.js} +1 -1
- package/src/assets/web-panel/assets/{index-zb7rVOhV.js → index-CW_G-MXw.js} +1 -1
- package/src/assets/web-panel/assets/{index-ATcSr_2O.js → index-CZ6Yt17L.js} +1 -1
- package/src/assets/web-panel/assets/{index-C9Y3k0HI.js → index-CeASi4fr.js} +1 -1
- package/src/assets/web-panel/assets/{index-B2U-ObMq.js → index-CgiECHu2.js} +1 -1
- package/src/assets/web-panel/assets/{index-Puq6Luf1.js → index-Cp8vhyZy.js} +1 -1
- package/src/assets/web-panel/assets/{index-BV551878.js → index-CwSf5pnf.js} +1 -1
- package/src/assets/web-panel/assets/{index-BowH1eLQ.js → index-D4_MuGkd.js} +1 -1
- package/src/assets/web-panel/assets/{index-B3CDgvNW.js → index-D9vU25ij.js} +1 -1
- package/src/assets/web-panel/assets/{index-WUrJ6S1j.js → index-DASluSqY.js} +1 -1
- package/src/assets/web-panel/assets/{index-CRLjEP1H.js → index-DLpIs_P_.js} +1 -1
- package/src/assets/web-panel/assets/index-DOZTSoS7.js +1 -0
- package/src/assets/web-panel/assets/{index-DT3zPSVX.js → index-DPdUNk1i.js} +1 -1
- package/src/assets/web-panel/assets/{index-BunaQCa0.js → index-DVsqvI4M.js} +1 -1
- package/src/assets/web-panel/assets/index-DhpvjpqI.js +1 -0
- package/src/assets/web-panel/assets/{index-CIpVrf5P.js → index-DmkMXwnR.js} +1 -1
- package/src/assets/web-panel/assets/{index-lJBjB1QX.js → index-DocdRcbd.js} +1 -1
- package/src/assets/web-panel/assets/{index-BEVm0lCS.js → index-Dyngbd29.js} +19 -19
- package/src/assets/web-panel/assets/{index-C4SJVjs4.js → index-GwdRUZ-x.js} +1 -1
- package/src/assets/web-panel/assets/{index-ukg99D1V.js → index-LvCBfTLo.js} +1 -1
- package/src/assets/web-panel/assets/{index-BfPL-m46.js → index-cpEli44X.js} +1 -1
- package/src/assets/web-panel/assets/{index-CpIGIB85.js → index-fzaMtSJ8.js} +1 -1
- package/src/assets/web-panel/assets/{index-BNZDILcO.js → index-pum7HYBA.js} +1 -1
- package/src/assets/web-panel/assets/{index-Dw1PyYPm.js → index-t8N1tSeX.js} +1 -1
- package/src/assets/web-panel/assets/{index-Cip8emOQ.js → index-uCbEN7cY.js} +1 -1
- package/src/assets/web-panel/assets/{index-DsvfrESp.js → index-wKTLbKyc.js} +1 -1
- package/src/assets/web-panel/assets/{index-B8BsdNV_.js → index-wV6iGdpY.js} +1 -1
- package/src/assets/web-panel/assets/{initDefaultProps-CYHMs1ag.js → initDefaultProps-V5Fo95FM.js} +1 -1
- package/src/assets/web-panel/assets/{motion-DDB2Ffk5.js → motion-BYWU0hUT.js} +1 -1
- package/src/assets/web-panel/assets/{move-Bg3cD-dX.js → move-Cr1M-J2h.js} +1 -1
- package/src/assets/web-panel/assets/{mtc-parser-B5nedjTS.js → mtc-parser-BysQKi2N.js} +1 -1
- package/src/assets/web-panel/assets/{omit-BHyuUILu.js → omit-D1zHU8GC.js} +1 -1
- package/src/assets/web-panel/assets/{pickAttrs-C9YQnEN9.js → pickAttrs-CUArxtfi.js} +1 -1
- package/src/assets/web-panel/assets/{placementArrow-DBUFYUe7.js → placementArrow-ChoYEys0.js} +1 -1
- package/src/assets/web-panel/assets/{responsiveObserve-nBs2Obnk.js → responsiveObserve-BQRs3Mo7.js} +1 -1
- package/src/assets/web-panel/assets/{slide-DkCEaXNU.js → slide-B8zbsCkg.js} +1 -1
- package/src/assets/web-panel/assets/{statusUtils-aqE1Wi6U.js → statusUtils-C2U8Gs6h.js} +1 -1
- package/src/assets/web-panel/assets/{styleChecker-CN5bhfHB.js → styleChecker-Dd8MgL_V.js} +1 -1
- package/src/assets/web-panel/assets/{useFlexGapSupport-B_oX_kvJ.js → useFlexGapSupport-hknqY5NH.js} +1 -1
- package/src/assets/web-panel/assets/{useFs-rCuXHeme.js → useFs-CLTAmcfw.js} +1 -1
- package/src/assets/web-panel/assets/{usePersonalDataHub-DZR9Abyd.js → usePersonalDataHub-ByegHbiB.js} +1 -1
- package/src/assets/web-panel/assets/{vnode-ConCYQlX.js → vnode-DqlAy5DP.js} +1 -1
- package/src/assets/web-panel/assets/{zoom-CUdDxG5M.js → zoom-DiXiztQn.js} +1 -1
- package/src/assets/web-panel/index.html +1 -1
- package/src/commands/agenda.js +115 -3
- package/src/commands/agent.js +6 -0
- package/src/data/changelog.json +13 -0
- package/src/gateways/terminal/PtyManager.js +45 -4
- package/src/gateways/ws/ws-server.js +10 -1
- package/src/harness/background-task-manager.js +70 -2
- package/src/harness/worktree-isolator.js +14 -3
- package/src/lib/agent-core.js +1 -0
- package/src/lib/agent-schedule-store.js +45 -22
- package/src/lib/hook-runner.js +6 -2
- package/src/lib/packer/pkg-config-generator.js +3 -1
- package/src/lib/plugin-runtime/bin.js +1148 -70
- package/src/lib/plugin-runtime/manifest.js +68 -12
- package/src/lib/plugin-runtime/scopes.js +20 -10
- package/src/lib/process-execution-broker/index.js +375 -48
- package/src/lib/process-execution-broker/platform-sandbox.js +3831 -276
- package/src/lib/process-execution-broker/windows-sandbox-helper.dll +0 -0
- package/src/lib/process-execution-broker/windows-sandbox-helper.exe +0 -0
- package/src/lib/process-execution-broker/windows-sandbox.cs +3856 -0
- package/src/lib/repl-bang-memorize.js +67 -10
- package/src/lib/slash-commands.js +27 -4
- package/src/repl/agent-repl.js +4 -3
- package/src/runtime/agent-core.js +376 -52
- package/src/runtime/agent-runtime.js +13 -1
- package/src/runtime/headless-runner.js +4 -3
- package/src/assets/web-panel/assets/Terminal-Cgb4eLB_.js +0 -3
- package/src/assets/web-panel/assets/devWarning-BzPwHnw8.js +0 -1
- package/src/assets/web-panel/assets/index-DacrAdc-.js +0 -1
- package/src/assets/web-panel/assets/index-EHzNJozo.js +0 -1
- package/src/lib/process-execution-broker/windows-sandbox.ps1 +0 -999
|
@@ -1,999 +0,0 @@
|
|
|
1
|
-
param(
|
|
2
|
-
[Parameter(Mandatory = $true)]
|
|
3
|
-
[string]$CacheExecutable,
|
|
4
|
-
|
|
5
|
-
[switch]$CompileOnly,
|
|
6
|
-
|
|
7
|
-
[Parameter(ValueFromRemainingArguments = $true)]
|
|
8
|
-
[string[]]$HelperArguments
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
$ErrorActionPreference = "Stop"
|
|
12
|
-
|
|
13
|
-
$nativeSource = @'
|
|
14
|
-
using System;
|
|
15
|
-
using System.Collections.Generic;
|
|
16
|
-
using System.ComponentModel;
|
|
17
|
-
using System.Globalization;
|
|
18
|
-
using System.IO;
|
|
19
|
-
using System.Runtime.InteropServices;
|
|
20
|
-
using System.Text;
|
|
21
|
-
using System.Web.Script.Serialization;
|
|
22
|
-
|
|
23
|
-
namespace ChainlessChain.WindowsSandbox
|
|
24
|
-
{
|
|
25
|
-
public static class Native
|
|
26
|
-
{
|
|
27
|
-
private const UInt32 TOKEN_ASSIGN_PRIMARY = 0x0001;
|
|
28
|
-
private const UInt32 TOKEN_DUPLICATE = 0x0002;
|
|
29
|
-
private const UInt32 TOKEN_QUERY = 0x0008;
|
|
30
|
-
private const UInt32 TOKEN_ADJUST_DEFAULT = 0x0080;
|
|
31
|
-
private const UInt32 TOKEN_ADJUST_SESSIONID = 0x0100;
|
|
32
|
-
|
|
33
|
-
private const UInt32 DISABLE_MAX_PRIVILEGE = 0x00000001;
|
|
34
|
-
private const UInt32 LUA_TOKEN = 0x00000004;
|
|
35
|
-
|
|
36
|
-
private const UInt32 CREATE_SUSPENDED = 0x00000004;
|
|
37
|
-
private const UInt32 DETACHED_PROCESS = 0x00000008;
|
|
38
|
-
private const UInt32 CREATE_NEW_PROCESS_GROUP = 0x00000200;
|
|
39
|
-
private const UInt32 CREATE_UNICODE_ENVIRONMENT = 0x00000400;
|
|
40
|
-
private const UInt32 EXTENDED_STARTUPINFO_PRESENT = 0x00080000;
|
|
41
|
-
private const UInt32 STARTF_USESHOWWINDOW = 0x00000001;
|
|
42
|
-
private const UInt32 STARTF_USESTDHANDLES = 0x00000100;
|
|
43
|
-
private const UInt16 SW_HIDE = 0;
|
|
44
|
-
private const UInt32 INFINITE = 0xffffffff;
|
|
45
|
-
private const UInt32 HANDLE_FLAG_INHERIT = 0x00000001;
|
|
46
|
-
private const Int32 ERROR_INSUFFICIENT_BUFFER = 122;
|
|
47
|
-
private static readonly IntPtr PROC_THREAD_ATTRIBUTE_HANDLE_LIST =
|
|
48
|
-
new IntPtr(0x00020002);
|
|
49
|
-
private const Byte CRT_FOPEN = 0x01;
|
|
50
|
-
private const Byte CRT_FPIPE = 0x08;
|
|
51
|
-
private const Byte CRT_FDEV = 0x40;
|
|
52
|
-
private const UInt32 FILE_TYPE_DISK = 0x0001;
|
|
53
|
-
private const UInt32 FILE_TYPE_CHAR = 0x0002;
|
|
54
|
-
private const UInt32 FILE_TYPE_PIPE = 0x0003;
|
|
55
|
-
private const UInt32 GENERIC_READ = 0x80000000;
|
|
56
|
-
private const UInt32 GENERIC_WRITE = 0x40000000;
|
|
57
|
-
private const UInt32 FILE_SHARE_READ = 0x00000001;
|
|
58
|
-
private const UInt32 FILE_SHARE_WRITE = 0x00000002;
|
|
59
|
-
private const UInt32 OPEN_EXISTING = 3;
|
|
60
|
-
private const UInt32 FILE_ATTRIBUTE_NORMAL = 0x00000080;
|
|
61
|
-
|
|
62
|
-
private const UInt32 JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002;
|
|
63
|
-
private const UInt32 JOB_OBJECT_LIMIT_ACTIVE_PROCESS = 0x00000008;
|
|
64
|
-
private const UInt32 JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100;
|
|
65
|
-
private const UInt32 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x00002000;
|
|
66
|
-
private const Int32 JobObjectExtendedLimitInformation = 9;
|
|
67
|
-
|
|
68
|
-
[StructLayout(LayoutKind.Sequential)]
|
|
69
|
-
private struct SECURITY_ATTRIBUTES
|
|
70
|
-
{
|
|
71
|
-
public UInt32 nLength;
|
|
72
|
-
public IntPtr lpSecurityDescriptor;
|
|
73
|
-
[MarshalAs(UnmanagedType.Bool)]
|
|
74
|
-
public bool bInheritHandle;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
78
|
-
private struct STARTUPINFO
|
|
79
|
-
{
|
|
80
|
-
public UInt32 cb;
|
|
81
|
-
public string lpReserved;
|
|
82
|
-
public string lpDesktop;
|
|
83
|
-
public string lpTitle;
|
|
84
|
-
public UInt32 dwX;
|
|
85
|
-
public UInt32 dwY;
|
|
86
|
-
public UInt32 dwXSize;
|
|
87
|
-
public UInt32 dwYSize;
|
|
88
|
-
public UInt32 dwXCountChars;
|
|
89
|
-
public UInt32 dwYCountChars;
|
|
90
|
-
public UInt32 dwFillAttribute;
|
|
91
|
-
public UInt32 dwFlags;
|
|
92
|
-
public UInt16 wShowWindow;
|
|
93
|
-
public UInt16 cbReserved2;
|
|
94
|
-
public IntPtr lpReserved2;
|
|
95
|
-
public IntPtr hStdInput;
|
|
96
|
-
public IntPtr hStdOutput;
|
|
97
|
-
public IntPtr hStdError;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
101
|
-
private struct STARTUPINFOEX
|
|
102
|
-
{
|
|
103
|
-
public STARTUPINFO StartupInfo;
|
|
104
|
-
public IntPtr lpAttributeList;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
[StructLayout(LayoutKind.Sequential)]
|
|
108
|
-
private struct PROCESS_INFORMATION
|
|
109
|
-
{
|
|
110
|
-
public IntPtr hProcess;
|
|
111
|
-
public IntPtr hThread;
|
|
112
|
-
public UInt32 dwProcessId;
|
|
113
|
-
public UInt32 dwThreadId;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
[StructLayout(LayoutKind.Sequential)]
|
|
117
|
-
private struct JOBOBJECT_BASIC_LIMIT_INFORMATION
|
|
118
|
-
{
|
|
119
|
-
public Int64 PerProcessUserTimeLimit;
|
|
120
|
-
public Int64 PerJobUserTimeLimit;
|
|
121
|
-
public UInt32 LimitFlags;
|
|
122
|
-
public UIntPtr MinimumWorkingSetSize;
|
|
123
|
-
public UIntPtr MaximumWorkingSetSize;
|
|
124
|
-
public UInt32 ActiveProcessLimit;
|
|
125
|
-
public UIntPtr Affinity;
|
|
126
|
-
public UInt32 PriorityClass;
|
|
127
|
-
public UInt32 SchedulingClass;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
[StructLayout(LayoutKind.Sequential)]
|
|
131
|
-
private struct IO_COUNTERS
|
|
132
|
-
{
|
|
133
|
-
public UInt64 ReadOperationCount;
|
|
134
|
-
public UInt64 WriteOperationCount;
|
|
135
|
-
public UInt64 OtherOperationCount;
|
|
136
|
-
public UInt64 ReadTransferCount;
|
|
137
|
-
public UInt64 WriteTransferCount;
|
|
138
|
-
public UInt64 OtherTransferCount;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
[StructLayout(LayoutKind.Sequential)]
|
|
142
|
-
private struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION
|
|
143
|
-
{
|
|
144
|
-
public JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
|
|
145
|
-
public IO_COUNTERS IoInfo;
|
|
146
|
-
public UIntPtr ProcessMemoryLimit;
|
|
147
|
-
public UIntPtr JobMemoryLimit;
|
|
148
|
-
public UIntPtr PeakProcessMemoryUsed;
|
|
149
|
-
public UIntPtr PeakJobMemoryUsed;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
[DllImport("kernel32.dll")]
|
|
153
|
-
private static extern IntPtr GetCurrentProcess();
|
|
154
|
-
|
|
155
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
156
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
157
|
-
private static extern bool CloseHandle(IntPtr handle);
|
|
158
|
-
|
|
159
|
-
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
160
|
-
private static extern IntPtr _get_osfhandle(Int32 fileDescriptor);
|
|
161
|
-
|
|
162
|
-
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
163
|
-
private static extern Int32 _close(Int32 fileDescriptor);
|
|
164
|
-
|
|
165
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
166
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
167
|
-
private static extern bool SetHandleInformation(
|
|
168
|
-
IntPtr handle,
|
|
169
|
-
UInt32 mask,
|
|
170
|
-
UInt32 flags);
|
|
171
|
-
|
|
172
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
173
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
174
|
-
private static extern bool InitializeProcThreadAttributeList(
|
|
175
|
-
IntPtr attributeList,
|
|
176
|
-
Int32 attributeCount,
|
|
177
|
-
Int32 flags,
|
|
178
|
-
ref IntPtr size);
|
|
179
|
-
|
|
180
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
181
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
182
|
-
private static extern bool UpdateProcThreadAttribute(
|
|
183
|
-
IntPtr attributeList,
|
|
184
|
-
UInt32 flags,
|
|
185
|
-
IntPtr attribute,
|
|
186
|
-
IntPtr value,
|
|
187
|
-
IntPtr size,
|
|
188
|
-
IntPtr previousValue,
|
|
189
|
-
IntPtr returnSize);
|
|
190
|
-
|
|
191
|
-
[DllImport("kernel32.dll")]
|
|
192
|
-
private static extern void DeleteProcThreadAttributeList(
|
|
193
|
-
IntPtr attributeList);
|
|
194
|
-
|
|
195
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
196
|
-
private static extern UInt32 GetFileType(IntPtr handle);
|
|
197
|
-
|
|
198
|
-
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
199
|
-
private static extern IntPtr CreateFile(
|
|
200
|
-
string fileName,
|
|
201
|
-
UInt32 desiredAccess,
|
|
202
|
-
UInt32 shareMode,
|
|
203
|
-
ref SECURITY_ATTRIBUTES securityAttributes,
|
|
204
|
-
UInt32 creationDisposition,
|
|
205
|
-
UInt32 flagsAndAttributes,
|
|
206
|
-
IntPtr templateFile);
|
|
207
|
-
|
|
208
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
209
|
-
private static extern UInt32 ResumeThread(IntPtr thread);
|
|
210
|
-
|
|
211
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
212
|
-
private static extern UInt32 WaitForSingleObject(IntPtr handle, UInt32 milliseconds);
|
|
213
|
-
|
|
214
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
215
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
216
|
-
private static extern bool GetExitCodeProcess(IntPtr process, out UInt32 exitCode);
|
|
217
|
-
|
|
218
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
219
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
220
|
-
private static extern bool TerminateProcess(IntPtr process, UInt32 exitCode);
|
|
221
|
-
|
|
222
|
-
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
223
|
-
private static extern IntPtr CreateJobObject(IntPtr attributes, string name);
|
|
224
|
-
|
|
225
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
226
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
227
|
-
private static extern bool SetInformationJobObject(
|
|
228
|
-
IntPtr job,
|
|
229
|
-
Int32 infoClass,
|
|
230
|
-
IntPtr info,
|
|
231
|
-
UInt32 infoLength);
|
|
232
|
-
|
|
233
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
234
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
235
|
-
private static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
|
|
236
|
-
|
|
237
|
-
[DllImport("advapi32.dll", SetLastError = true)]
|
|
238
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
239
|
-
private static extern bool OpenProcessToken(
|
|
240
|
-
IntPtr process,
|
|
241
|
-
UInt32 desiredAccess,
|
|
242
|
-
out IntPtr token);
|
|
243
|
-
|
|
244
|
-
[DllImport("advapi32.dll", SetLastError = true)]
|
|
245
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
246
|
-
private static extern bool CreateRestrictedToken(
|
|
247
|
-
IntPtr existingToken,
|
|
248
|
-
UInt32 flags,
|
|
249
|
-
UInt32 disableSidCount,
|
|
250
|
-
IntPtr sidsToDisable,
|
|
251
|
-
UInt32 deletePrivilegeCount,
|
|
252
|
-
IntPtr privilegesToDelete,
|
|
253
|
-
UInt32 restrictedSidCount,
|
|
254
|
-
IntPtr sidsToRestrict,
|
|
255
|
-
out IntPtr restrictedToken);
|
|
256
|
-
|
|
257
|
-
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
258
|
-
[return: MarshalAs(UnmanagedType.Bool)]
|
|
259
|
-
private static extern bool CreateProcessAsUser(
|
|
260
|
-
IntPtr token,
|
|
261
|
-
string applicationName,
|
|
262
|
-
StringBuilder commandLine,
|
|
263
|
-
IntPtr processAttributes,
|
|
264
|
-
IntPtr threadAttributes,
|
|
265
|
-
[MarshalAs(UnmanagedType.Bool)] bool inheritHandles,
|
|
266
|
-
UInt32 creationFlags,
|
|
267
|
-
IntPtr environment,
|
|
268
|
-
string currentDirectory,
|
|
269
|
-
ref STARTUPINFOEX startupInfo,
|
|
270
|
-
out PROCESS_INFORMATION processInformation);
|
|
271
|
-
|
|
272
|
-
[DllImport("kernel32.dll", SetLastError = true)]
|
|
273
|
-
private static extern IntPtr GetStdHandle(Int32 standardHandle);
|
|
274
|
-
|
|
275
|
-
private static void ThrowLastError(string operation)
|
|
276
|
-
{
|
|
277
|
-
int code = Marshal.GetLastWin32Error();
|
|
278
|
-
string systemMessage = new Win32Exception(code).Message;
|
|
279
|
-
throw new Win32Exception(
|
|
280
|
-
code,
|
|
281
|
-
String.Format(
|
|
282
|
-
CultureInfo.InvariantCulture,
|
|
283
|
-
"{0} failed (win32={1}: {2})",
|
|
284
|
-
operation,
|
|
285
|
-
code,
|
|
286
|
-
systemMessage));
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
public static string QuoteArgument(string value)
|
|
290
|
-
{
|
|
291
|
-
if (value == null) value = String.Empty;
|
|
292
|
-
if (value.Length > 0 &&
|
|
293
|
-
value.IndexOfAny(new[] { ' ', '\t', '\n', '\v', '"' }) < 0)
|
|
294
|
-
{
|
|
295
|
-
return value;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
StringBuilder result = new StringBuilder();
|
|
299
|
-
result.Append('"');
|
|
300
|
-
int backslashes = 0;
|
|
301
|
-
foreach (char current in value)
|
|
302
|
-
{
|
|
303
|
-
if (current == '\\')
|
|
304
|
-
{
|
|
305
|
-
backslashes++;
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
if (current == '"')
|
|
309
|
-
{
|
|
310
|
-
result.Append('\\', backslashes * 2 + 1);
|
|
311
|
-
result.Append('"');
|
|
312
|
-
backslashes = 0;
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
result.Append('\\', backslashes);
|
|
316
|
-
backslashes = 0;
|
|
317
|
-
result.Append(current);
|
|
318
|
-
}
|
|
319
|
-
result.Append('\\', backslashes * 2);
|
|
320
|
-
result.Append('"');
|
|
321
|
-
return result.ToString();
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
public static string BuildCommandLine(string application, string[] arguments)
|
|
325
|
-
{
|
|
326
|
-
StringBuilder line = new StringBuilder(QuoteArgument(application));
|
|
327
|
-
if (arguments != null)
|
|
328
|
-
{
|
|
329
|
-
foreach (string argument in arguments)
|
|
330
|
-
{
|
|
331
|
-
line.Append(' ');
|
|
332
|
-
line.Append(QuoteArgument(argument));
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return line.ToString();
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
private static string BuildCreateProcessCommandLine(
|
|
339
|
-
string application,
|
|
340
|
-
string[] arguments)
|
|
341
|
-
{
|
|
342
|
-
// cmd.exe /s /c has its own quoting contract: the command after
|
|
343
|
-
// /c must be surrounded by one literal quote pair while quotes
|
|
344
|
-
// inside that command remain untouched. Applying the normal CRT
|
|
345
|
-
// backslash escaping here makes cmd.exe treat those backslashes as
|
|
346
|
-
// data, which silently breaks commands such as:
|
|
347
|
-
// node -e "process.stdout.write('value')"
|
|
348
|
-
if (
|
|
349
|
-
Path.GetFileName(application).Equals(
|
|
350
|
-
"cmd.exe",
|
|
351
|
-
StringComparison.OrdinalIgnoreCase) &&
|
|
352
|
-
arguments != null &&
|
|
353
|
-
arguments.Length == 4 &&
|
|
354
|
-
arguments[0].Equals("/d", StringComparison.OrdinalIgnoreCase) &&
|
|
355
|
-
arguments[1].Equals("/s", StringComparison.OrdinalIgnoreCase) &&
|
|
356
|
-
arguments[2].Equals("/c", StringComparison.OrdinalIgnoreCase))
|
|
357
|
-
{
|
|
358
|
-
return
|
|
359
|
-
QuoteArgument(application) +
|
|
360
|
-
" /d /s /c \"" +
|
|
361
|
-
arguments[3] +
|
|
362
|
-
"\"";
|
|
363
|
-
}
|
|
364
|
-
return BuildCommandLine(application, arguments);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
private static string ResolveApplication(string application)
|
|
368
|
-
{
|
|
369
|
-
if (String.IsNullOrWhiteSpace(application))
|
|
370
|
-
throw new ArgumentException("Target application is empty");
|
|
371
|
-
|
|
372
|
-
if (Path.IsPathRooted(application) || application.IndexOf('\\') >= 0 ||
|
|
373
|
-
application.IndexOf('/') >= 0)
|
|
374
|
-
{
|
|
375
|
-
string rooted = Path.GetFullPath(application);
|
|
376
|
-
if (File.Exists(rooted)) return rooted;
|
|
377
|
-
throw new FileNotFoundException("Target application was not found", rooted);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
string[] extensions;
|
|
381
|
-
if (Path.HasExtension(application))
|
|
382
|
-
{
|
|
383
|
-
extensions = new[] { String.Empty };
|
|
384
|
-
}
|
|
385
|
-
else
|
|
386
|
-
{
|
|
387
|
-
string pathExt = Environment.GetEnvironmentVariable("PATHEXT") ??
|
|
388
|
-
".COM;.EXE;.BAT;.CMD";
|
|
389
|
-
string[] configured = pathExt.Split(
|
|
390
|
-
new[] { ';' },
|
|
391
|
-
StringSplitOptions.RemoveEmptyEntries);
|
|
392
|
-
extensions = new string[configured.Length + 1];
|
|
393
|
-
extensions[0] = String.Empty;
|
|
394
|
-
Array.Copy(configured, 0, extensions, 1, configured.Length);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
string searchPath = Environment.GetEnvironmentVariable("PATH") ?? String.Empty;
|
|
398
|
-
foreach (string directory in searchPath.Split(Path.PathSeparator))
|
|
399
|
-
{
|
|
400
|
-
if (String.IsNullOrWhiteSpace(directory)) continue;
|
|
401
|
-
foreach (string extension in extensions)
|
|
402
|
-
{
|
|
403
|
-
string candidate = Path.Combine(
|
|
404
|
-
directory.Trim().Trim('"'),
|
|
405
|
-
application + extension);
|
|
406
|
-
if (File.Exists(candidate)) return Path.GetFullPath(candidate);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
throw new FileNotFoundException(
|
|
410
|
-
"Target application was not found on PATH",
|
|
411
|
-
application);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
private static Byte GetCrtFlags(IntPtr handle)
|
|
415
|
-
{
|
|
416
|
-
UInt32 fileType = GetFileType(handle);
|
|
417
|
-
if (fileType == FILE_TYPE_DISK) return CRT_FOPEN;
|
|
418
|
-
if (fileType == FILE_TYPE_PIPE)
|
|
419
|
-
return CRT_FOPEN | CRT_FPIPE;
|
|
420
|
-
if (fileType == FILE_TYPE_CHAR)
|
|
421
|
-
return CRT_FOPEN | CRT_FDEV;
|
|
422
|
-
throw new InvalidDataException(
|
|
423
|
-
"Inherited descriptor has an unsupported handle type");
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
private static bool IsInvalidHandle(IntPtr handle)
|
|
427
|
-
{
|
|
428
|
-
return
|
|
429
|
-
handle == IntPtr.Zero ||
|
|
430
|
-
handle == new IntPtr(-1) ||
|
|
431
|
-
handle == new IntPtr(-2);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
private static IntPtr PrepareStandardHandle(
|
|
435
|
-
Int32 standardHandle,
|
|
436
|
-
UInt32 fallbackAccess,
|
|
437
|
-
List<IntPtr> ownedHandles)
|
|
438
|
-
{
|
|
439
|
-
IntPtr handle = GetStdHandle(standardHandle);
|
|
440
|
-
if (
|
|
441
|
-
!IsInvalidHandle(handle) &&
|
|
442
|
-
SetHandleInformation(
|
|
443
|
-
handle,
|
|
444
|
-
HANDLE_FLAG_INHERIT,
|
|
445
|
-
HANDLE_FLAG_INHERIT))
|
|
446
|
-
{
|
|
447
|
-
return handle;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
SECURITY_ATTRIBUTES attributes = new SECURITY_ATTRIBUTES();
|
|
451
|
-
attributes.nLength = checked(
|
|
452
|
-
(UInt32)Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES)));
|
|
453
|
-
attributes.bInheritHandle = true;
|
|
454
|
-
IntPtr fallback = CreateFile(
|
|
455
|
-
"NUL",
|
|
456
|
-
fallbackAccess,
|
|
457
|
-
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
458
|
-
ref attributes,
|
|
459
|
-
OPEN_EXISTING,
|
|
460
|
-
FILE_ATTRIBUTE_NORMAL,
|
|
461
|
-
IntPtr.Zero);
|
|
462
|
-
if (IsInvalidHandle(fallback))
|
|
463
|
-
ThrowLastError("CreateFile(NUL)");
|
|
464
|
-
ownedHandles.Add(fallback);
|
|
465
|
-
return fallback;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
private static IntPtr BuildNodeDescriptorTable(
|
|
469
|
-
int nodeIpcFd,
|
|
470
|
-
IntPtr standardInput,
|
|
471
|
-
IntPtr standardOutput,
|
|
472
|
-
IntPtr standardError,
|
|
473
|
-
out UInt16 descriptorBytes)
|
|
474
|
-
{
|
|
475
|
-
descriptorBytes = 0;
|
|
476
|
-
// stdin/stdout/stderr are transferred by STARTUPINFO. Only attach
|
|
477
|
-
// the CRT descriptor table when Node needs a descriptor above fd 2
|
|
478
|
-
// (its fd 3 IPC channel); this also preserves the previously proven
|
|
479
|
-
// non-IPC startup contract on hosted Windows runners.
|
|
480
|
-
if (nodeIpcFd < 0) return IntPtr.Zero;
|
|
481
|
-
if (nodeIpcFd > 255)
|
|
482
|
-
throw new InvalidDataException(
|
|
483
|
-
"Node IPC descriptor is outside the CRT table range");
|
|
484
|
-
|
|
485
|
-
int descriptorCount = Math.Max(3, nodeIpcFd + 1);
|
|
486
|
-
int bufferSize = checked(
|
|
487
|
-
sizeof(Int32) +
|
|
488
|
-
descriptorCount +
|
|
489
|
-
IntPtr.Size * descriptorCount);
|
|
490
|
-
IntPtr buffer = Marshal.AllocHGlobal(bufferSize);
|
|
491
|
-
try
|
|
492
|
-
{
|
|
493
|
-
for (int offset = 0; offset < bufferSize; offset++)
|
|
494
|
-
Marshal.WriteByte(buffer, offset, 0);
|
|
495
|
-
Marshal.WriteInt32(buffer, descriptorCount);
|
|
496
|
-
for (int fd = 0; fd < descriptorCount; fd++)
|
|
497
|
-
{
|
|
498
|
-
IntPtr handle;
|
|
499
|
-
if (fd == 0)
|
|
500
|
-
handle = standardInput;
|
|
501
|
-
else if (fd == 1)
|
|
502
|
-
handle = standardOutput;
|
|
503
|
-
else if (fd == 2)
|
|
504
|
-
handle = standardError;
|
|
505
|
-
else if (fd == nodeIpcFd)
|
|
506
|
-
handle = _get_osfhandle(fd);
|
|
507
|
-
else
|
|
508
|
-
handle = new IntPtr(-1);
|
|
509
|
-
|
|
510
|
-
int handleOffset = checked(
|
|
511
|
-
sizeof(Int32) +
|
|
512
|
-
descriptorCount +
|
|
513
|
-
IntPtr.Size * fd);
|
|
514
|
-
if (
|
|
515
|
-
handle == IntPtr.Zero ||
|
|
516
|
-
handle == new IntPtr(-1) ||
|
|
517
|
-
handle == new IntPtr(-2))
|
|
518
|
-
{
|
|
519
|
-
if (fd == nodeIpcFd)
|
|
520
|
-
throw new InvalidDataException(
|
|
521
|
-
"Node IPC descriptor has no inherited OS handle");
|
|
522
|
-
if (IntPtr.Size == sizeof(Int64))
|
|
523
|
-
Marshal.WriteInt64(buffer, handleOffset, -1);
|
|
524
|
-
else
|
|
525
|
-
Marshal.WriteInt32(buffer, handleOffset, -1);
|
|
526
|
-
continue;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
if (!SetHandleInformation(
|
|
530
|
-
handle,
|
|
531
|
-
HANDLE_FLAG_INHERIT,
|
|
532
|
-
HANDLE_FLAG_INHERIT))
|
|
533
|
-
ThrowLastError("SetHandleInformation(CRT descriptor)");
|
|
534
|
-
Marshal.WriteByte(
|
|
535
|
-
buffer,
|
|
536
|
-
sizeof(Int32) + fd,
|
|
537
|
-
GetCrtFlags(handle));
|
|
538
|
-
if (IntPtr.Size == sizeof(Int64))
|
|
539
|
-
Marshal.WriteInt64(
|
|
540
|
-
buffer,
|
|
541
|
-
handleOffset,
|
|
542
|
-
handle.ToInt64());
|
|
543
|
-
else
|
|
544
|
-
Marshal.WriteInt32(
|
|
545
|
-
buffer,
|
|
546
|
-
handleOffset,
|
|
547
|
-
handle.ToInt32());
|
|
548
|
-
}
|
|
549
|
-
descriptorBytes = checked((UInt16)bufferSize);
|
|
550
|
-
return buffer;
|
|
551
|
-
}
|
|
552
|
-
catch
|
|
553
|
-
{
|
|
554
|
-
Marshal.FreeHGlobal(buffer);
|
|
555
|
-
throw;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
private static IntPtr BuildInheritedHandleList(
|
|
560
|
-
IntPtr standardInput,
|
|
561
|
-
IntPtr standardOutput,
|
|
562
|
-
IntPtr standardError,
|
|
563
|
-
int nodeIpcFd,
|
|
564
|
-
out IntPtr handleBytes)
|
|
565
|
-
{
|
|
566
|
-
List<IntPtr> handles = new List<IntPtr>();
|
|
567
|
-
handles.Add(standardInput);
|
|
568
|
-
if (!handles.Contains(standardOutput))
|
|
569
|
-
handles.Add(standardOutput);
|
|
570
|
-
if (!handles.Contains(standardError))
|
|
571
|
-
handles.Add(standardError);
|
|
572
|
-
|
|
573
|
-
if (nodeIpcFd >= 0)
|
|
574
|
-
{
|
|
575
|
-
IntPtr ipcHandle = _get_osfhandle(nodeIpcFd);
|
|
576
|
-
if (IsInvalidHandle(ipcHandle))
|
|
577
|
-
throw new InvalidDataException(
|
|
578
|
-
"Node IPC descriptor has no inherited OS handle");
|
|
579
|
-
if (!handles.Contains(ipcHandle))
|
|
580
|
-
handles.Add(ipcHandle);
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
foreach (IntPtr handle in handles)
|
|
584
|
-
{
|
|
585
|
-
if (IsInvalidHandle(handle))
|
|
586
|
-
throw new InvalidDataException(
|
|
587
|
-
"Inherited standard handle is invalid");
|
|
588
|
-
if (!SetHandleInformation(
|
|
589
|
-
handle,
|
|
590
|
-
HANDLE_FLAG_INHERIT,
|
|
591
|
-
HANDLE_FLAG_INHERIT))
|
|
592
|
-
ThrowLastError("SetHandleInformation(handle list)");
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
int bufferSize = checked(handles.Count * IntPtr.Size);
|
|
596
|
-
IntPtr buffer = Marshal.AllocHGlobal(bufferSize);
|
|
597
|
-
try
|
|
598
|
-
{
|
|
599
|
-
for (int index = 0; index < handles.Count; index++)
|
|
600
|
-
Marshal.WriteIntPtr(
|
|
601
|
-
buffer,
|
|
602
|
-
checked(index * IntPtr.Size),
|
|
603
|
-
handles[index]);
|
|
604
|
-
handleBytes = new IntPtr(bufferSize);
|
|
605
|
-
return buffer;
|
|
606
|
-
}
|
|
607
|
-
catch
|
|
608
|
-
{
|
|
609
|
-
Marshal.FreeHGlobal(buffer);
|
|
610
|
-
throw;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
private static IntPtr BuildProcessAttributeList(
|
|
615
|
-
IntPtr inheritedHandles,
|
|
616
|
-
IntPtr inheritedHandleBytes)
|
|
617
|
-
{
|
|
618
|
-
IntPtr attributeBytes = IntPtr.Zero;
|
|
619
|
-
bool probeSucceeded = InitializeProcThreadAttributeList(
|
|
620
|
-
IntPtr.Zero,
|
|
621
|
-
1,
|
|
622
|
-
0,
|
|
623
|
-
ref attributeBytes);
|
|
624
|
-
int probeError = Marshal.GetLastWin32Error();
|
|
625
|
-
if (probeSucceeded || probeError != ERROR_INSUFFICIENT_BUFFER)
|
|
626
|
-
throw new Win32Exception(
|
|
627
|
-
probeError,
|
|
628
|
-
"InitializeProcThreadAttributeList(size) failed");
|
|
629
|
-
|
|
630
|
-
IntPtr attributeList = Marshal.AllocHGlobal(attributeBytes);
|
|
631
|
-
bool initialized = false;
|
|
632
|
-
try
|
|
633
|
-
{
|
|
634
|
-
if (!InitializeProcThreadAttributeList(
|
|
635
|
-
attributeList,
|
|
636
|
-
1,
|
|
637
|
-
0,
|
|
638
|
-
ref attributeBytes))
|
|
639
|
-
ThrowLastError("InitializeProcThreadAttributeList");
|
|
640
|
-
initialized = true;
|
|
641
|
-
if (!UpdateProcThreadAttribute(
|
|
642
|
-
attributeList,
|
|
643
|
-
0,
|
|
644
|
-
PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
|
|
645
|
-
inheritedHandles,
|
|
646
|
-
inheritedHandleBytes,
|
|
647
|
-
IntPtr.Zero,
|
|
648
|
-
IntPtr.Zero))
|
|
649
|
-
ThrowLastError("UpdateProcThreadAttribute(handle list)");
|
|
650
|
-
return attributeList;
|
|
651
|
-
}
|
|
652
|
-
catch
|
|
653
|
-
{
|
|
654
|
-
if (initialized)
|
|
655
|
-
DeleteProcThreadAttributeList(attributeList);
|
|
656
|
-
Marshal.FreeHGlobal(attributeList);
|
|
657
|
-
throw;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
public static int Run(
|
|
662
|
-
string application,
|
|
663
|
-
string[] arguments,
|
|
664
|
-
int cpuSeconds,
|
|
665
|
-
long processMemoryBytes,
|
|
666
|
-
int activeProcessLimit,
|
|
667
|
-
int nodeIpcFd,
|
|
668
|
-
bool detached,
|
|
669
|
-
bool windowsHide,
|
|
670
|
-
string identityPath)
|
|
671
|
-
{
|
|
672
|
-
application = ResolveApplication(application);
|
|
673
|
-
string extension = Path.GetExtension(application);
|
|
674
|
-
if (extension.Equals(".cmd", StringComparison.OrdinalIgnoreCase) ||
|
|
675
|
-
extension.Equals(".bat", StringComparison.OrdinalIgnoreCase))
|
|
676
|
-
{
|
|
677
|
-
string commandText = BuildCommandLine(application, arguments);
|
|
678
|
-
application = ResolveApplication(
|
|
679
|
-
Environment.GetEnvironmentVariable("ComSpec") ?? "cmd.exe");
|
|
680
|
-
arguments = new[] { "/d", "/s", "/c", commandText };
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
IntPtr sourceToken = IntPtr.Zero;
|
|
684
|
-
IntPtr restrictedToken = IntPtr.Zero;
|
|
685
|
-
IntPtr job = IntPtr.Zero;
|
|
686
|
-
IntPtr limitBuffer = IntPtr.Zero;
|
|
687
|
-
IntPtr descriptorBuffer = IntPtr.Zero;
|
|
688
|
-
IntPtr inheritedHandleBuffer = IntPtr.Zero;
|
|
689
|
-
IntPtr attributeList = IntPtr.Zero;
|
|
690
|
-
List<IntPtr> ownedStandardHandles = new List<IntPtr>();
|
|
691
|
-
PROCESS_INFORMATION processInfo = new PROCESS_INFORMATION();
|
|
692
|
-
|
|
693
|
-
try
|
|
694
|
-
{
|
|
695
|
-
UInt32 tokenAccess =
|
|
696
|
-
TOKEN_ASSIGN_PRIMARY |
|
|
697
|
-
TOKEN_DUPLICATE |
|
|
698
|
-
TOKEN_QUERY |
|
|
699
|
-
TOKEN_ADJUST_DEFAULT |
|
|
700
|
-
TOKEN_ADJUST_SESSIONID;
|
|
701
|
-
if (!OpenProcessToken(GetCurrentProcess(), tokenAccess, out sourceToken))
|
|
702
|
-
ThrowLastError("OpenProcessToken");
|
|
703
|
-
|
|
704
|
-
if (!CreateRestrictedToken(
|
|
705
|
-
sourceToken,
|
|
706
|
-
DISABLE_MAX_PRIVILEGE | LUA_TOKEN,
|
|
707
|
-
0,
|
|
708
|
-
IntPtr.Zero,
|
|
709
|
-
0,
|
|
710
|
-
IntPtr.Zero,
|
|
711
|
-
0,
|
|
712
|
-
IntPtr.Zero,
|
|
713
|
-
out restrictedToken))
|
|
714
|
-
ThrowLastError("CreateRestrictedToken");
|
|
715
|
-
|
|
716
|
-
job = CreateJobObject(IntPtr.Zero, null);
|
|
717
|
-
if (job == IntPtr.Zero) ThrowLastError("CreateJobObject");
|
|
718
|
-
|
|
719
|
-
JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits =
|
|
720
|
-
new JOBOBJECT_EXTENDED_LIMIT_INFORMATION();
|
|
721
|
-
limits.BasicLimitInformation.LimitFlags =
|
|
722
|
-
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
|
|
723
|
-
if (cpuSeconds > 0)
|
|
724
|
-
{
|
|
725
|
-
limits.BasicLimitInformation.LimitFlags |=
|
|
726
|
-
JOB_OBJECT_LIMIT_PROCESS_TIME;
|
|
727
|
-
limits.BasicLimitInformation.PerProcessUserTimeLimit =
|
|
728
|
-
checked((long)cpuSeconds * 10000000L);
|
|
729
|
-
}
|
|
730
|
-
if (activeProcessLimit > 0)
|
|
731
|
-
{
|
|
732
|
-
limits.BasicLimitInformation.LimitFlags |=
|
|
733
|
-
JOB_OBJECT_LIMIT_ACTIVE_PROCESS;
|
|
734
|
-
limits.BasicLimitInformation.ActiveProcessLimit =
|
|
735
|
-
checked((UInt32)activeProcessLimit);
|
|
736
|
-
}
|
|
737
|
-
if (processMemoryBytes > 0)
|
|
738
|
-
{
|
|
739
|
-
limits.BasicLimitInformation.LimitFlags |=
|
|
740
|
-
JOB_OBJECT_LIMIT_PROCESS_MEMORY;
|
|
741
|
-
limits.ProcessMemoryLimit =
|
|
742
|
-
new UIntPtr(checked((UInt64)processMemoryBytes));
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
int limitSize = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
|
|
746
|
-
limitBuffer = Marshal.AllocHGlobal(limitSize);
|
|
747
|
-
Marshal.StructureToPtr(limits, limitBuffer, false);
|
|
748
|
-
if (!SetInformationJobObject(
|
|
749
|
-
job,
|
|
750
|
-
JobObjectExtendedLimitInformation,
|
|
751
|
-
limitBuffer,
|
|
752
|
-
checked((UInt32)limitSize)))
|
|
753
|
-
ThrowLastError("SetInformationJobObject");
|
|
754
|
-
|
|
755
|
-
// Node/libuv communicates Windows stdio entries above fd 2
|
|
756
|
-
// (including its fd 3 IPC channel) through the CRT descriptor
|
|
757
|
-
// table in STARTUPINFO.cbReserved2/lpReserved2. Standard
|
|
758
|
-
// descriptors remain in STARTUPINFO's dedicated handle fields.
|
|
759
|
-
STARTUPINFOEX startup = new STARTUPINFOEX();
|
|
760
|
-
startup.StartupInfo.cb = checked(
|
|
761
|
-
(UInt32)Marshal.SizeOf(typeof(STARTUPINFOEX)));
|
|
762
|
-
startup.StartupInfo.dwFlags = STARTF_USESTDHANDLES;
|
|
763
|
-
if (windowsHide)
|
|
764
|
-
{
|
|
765
|
-
startup.StartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
|
|
766
|
-
startup.StartupInfo.wShowWindow = SW_HIDE;
|
|
767
|
-
}
|
|
768
|
-
startup.StartupInfo.hStdInput = PrepareStandardHandle(
|
|
769
|
-
-10,
|
|
770
|
-
GENERIC_READ,
|
|
771
|
-
ownedStandardHandles);
|
|
772
|
-
startup.StartupInfo.hStdOutput = PrepareStandardHandle(
|
|
773
|
-
-11,
|
|
774
|
-
GENERIC_WRITE,
|
|
775
|
-
ownedStandardHandles);
|
|
776
|
-
startup.StartupInfo.hStdError = PrepareStandardHandle(
|
|
777
|
-
-12,
|
|
778
|
-
GENERIC_WRITE,
|
|
779
|
-
ownedStandardHandles);
|
|
780
|
-
UInt16 descriptorBytes;
|
|
781
|
-
descriptorBuffer = BuildNodeDescriptorTable(
|
|
782
|
-
nodeIpcFd,
|
|
783
|
-
startup.StartupInfo.hStdInput,
|
|
784
|
-
startup.StartupInfo.hStdOutput,
|
|
785
|
-
startup.StartupInfo.hStdError,
|
|
786
|
-
out descriptorBytes);
|
|
787
|
-
startup.StartupInfo.cbReserved2 = descriptorBytes;
|
|
788
|
-
startup.StartupInfo.lpReserved2 = descriptorBuffer;
|
|
789
|
-
|
|
790
|
-
IntPtr inheritedHandleBytes;
|
|
791
|
-
inheritedHandleBuffer = BuildInheritedHandleList(
|
|
792
|
-
startup.StartupInfo.hStdInput,
|
|
793
|
-
startup.StartupInfo.hStdOutput,
|
|
794
|
-
startup.StartupInfo.hStdError,
|
|
795
|
-
nodeIpcFd,
|
|
796
|
-
out inheritedHandleBytes);
|
|
797
|
-
attributeList = BuildProcessAttributeList(
|
|
798
|
-
inheritedHandleBuffer,
|
|
799
|
-
inheritedHandleBytes);
|
|
800
|
-
startup.lpAttributeList = attributeList;
|
|
801
|
-
|
|
802
|
-
StringBuilder commandLine =
|
|
803
|
-
new StringBuilder(
|
|
804
|
-
BuildCreateProcessCommandLine(application, arguments));
|
|
805
|
-
UInt32 creationFlags =
|
|
806
|
-
CREATE_SUSPENDED |
|
|
807
|
-
CREATE_UNICODE_ENVIRONMENT |
|
|
808
|
-
EXTENDED_STARTUPINFO_PRESENT;
|
|
809
|
-
if (detached)
|
|
810
|
-
creationFlags |= DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP;
|
|
811
|
-
if (!CreateProcessAsUser(
|
|
812
|
-
restrictedToken,
|
|
813
|
-
application,
|
|
814
|
-
commandLine,
|
|
815
|
-
IntPtr.Zero,
|
|
816
|
-
IntPtr.Zero,
|
|
817
|
-
true,
|
|
818
|
-
creationFlags,
|
|
819
|
-
IntPtr.Zero,
|
|
820
|
-
Environment.CurrentDirectory,
|
|
821
|
-
ref startup,
|
|
822
|
-
out processInfo))
|
|
823
|
-
ThrowLastError("CreateProcessAsUser");
|
|
824
|
-
|
|
825
|
-
// The target now owns its inherited copy of the duplex IPC
|
|
826
|
-
// pipe. Close the helper's CRT descriptor so process.disconnect
|
|
827
|
-
// and channel EOF retain native Node child semantics even while
|
|
828
|
-
// the helper continues waiting on the target process handle.
|
|
829
|
-
if (nodeIpcFd >= 0 && _close(nodeIpcFd) != 0)
|
|
830
|
-
{
|
|
831
|
-
TerminateProcess(processInfo.hProcess, 125);
|
|
832
|
-
throw new IOException(
|
|
833
|
-
"Closing the Windows sandbox IPC relay descriptor failed");
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
if (!AssignProcessToJobObject(job, processInfo.hProcess))
|
|
837
|
-
{
|
|
838
|
-
TerminateProcess(processInfo.hProcess, 125);
|
|
839
|
-
ThrowLastError("AssignProcessToJobObject");
|
|
840
|
-
}
|
|
841
|
-
if (ResumeThread(processInfo.hThread) == UInt32.MaxValue)
|
|
842
|
-
{
|
|
843
|
-
TerminateProcess(processInfo.hProcess, 125);
|
|
844
|
-
ThrowLastError("ResumeThread");
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
if (!String.IsNullOrWhiteSpace(identityPath))
|
|
848
|
-
{
|
|
849
|
-
string identity = String.Format(
|
|
850
|
-
CultureInfo.InvariantCulture,
|
|
851
|
-
"{{\"targetPid\":{0},\"helperPid\":{1}}}",
|
|
852
|
-
processInfo.dwProcessId,
|
|
853
|
-
System.Diagnostics.Process.GetCurrentProcess().Id);
|
|
854
|
-
using (FileStream stream = new FileStream(
|
|
855
|
-
identityPath,
|
|
856
|
-
FileMode.CreateNew,
|
|
857
|
-
FileAccess.Write,
|
|
858
|
-
FileShare.Read))
|
|
859
|
-
using (StreamWriter writer = new StreamWriter(
|
|
860
|
-
stream,
|
|
861
|
-
new UTF8Encoding(false)))
|
|
862
|
-
{
|
|
863
|
-
writer.Write(identity);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
WaitForSingleObject(processInfo.hProcess, INFINITE);
|
|
868
|
-
UInt32 exitCode;
|
|
869
|
-
if (!GetExitCodeProcess(processInfo.hProcess, out exitCode))
|
|
870
|
-
ThrowLastError("GetExitCodeProcess");
|
|
871
|
-
return unchecked((int)exitCode);
|
|
872
|
-
}
|
|
873
|
-
finally
|
|
874
|
-
{
|
|
875
|
-
if (processInfo.hThread != IntPtr.Zero) CloseHandle(processInfo.hThread);
|
|
876
|
-
if (processInfo.hProcess != IntPtr.Zero) CloseHandle(processInfo.hProcess);
|
|
877
|
-
if (attributeList != IntPtr.Zero)
|
|
878
|
-
{
|
|
879
|
-
DeleteProcThreadAttributeList(attributeList);
|
|
880
|
-
Marshal.FreeHGlobal(attributeList);
|
|
881
|
-
}
|
|
882
|
-
if (inheritedHandleBuffer != IntPtr.Zero)
|
|
883
|
-
Marshal.FreeHGlobal(inheritedHandleBuffer);
|
|
884
|
-
if (descriptorBuffer != IntPtr.Zero)
|
|
885
|
-
Marshal.FreeHGlobal(descriptorBuffer);
|
|
886
|
-
foreach (IntPtr handle in ownedStandardHandles)
|
|
887
|
-
CloseHandle(handle);
|
|
888
|
-
if (limitBuffer != IntPtr.Zero) Marshal.FreeHGlobal(limitBuffer);
|
|
889
|
-
if (job != IntPtr.Zero) CloseHandle(job);
|
|
890
|
-
if (restrictedToken != IntPtr.Zero) CloseHandle(restrictedToken);
|
|
891
|
-
if (sourceToken != IntPtr.Zero) CloseHandle(sourceToken);
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
public static class Program
|
|
897
|
-
{
|
|
898
|
-
private sealed class LaunchSpec
|
|
899
|
-
{
|
|
900
|
-
public int cpuSeconds { get; set; }
|
|
901
|
-
public long processMemoryBytes { get; set; }
|
|
902
|
-
public int activeProcessLimit { get; set; }
|
|
903
|
-
public string command { get; set; }
|
|
904
|
-
public string[] args { get; set; }
|
|
905
|
-
public int nodeIpcFd { get; set; }
|
|
906
|
-
public bool detached { get; set; }
|
|
907
|
-
public bool windowsHide { get; set; }
|
|
908
|
-
public string identityPath { get; set; }
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
public static int Main(string[] args)
|
|
912
|
-
{
|
|
913
|
-
LaunchSpec spec = null;
|
|
914
|
-
try
|
|
915
|
-
{
|
|
916
|
-
if (args == null || args.Length != 1)
|
|
917
|
-
throw new ArgumentException("Expected one encoded launch payload");
|
|
918
|
-
|
|
919
|
-
string json = Encoding.UTF8.GetString(
|
|
920
|
-
Convert.FromBase64String(args[0]));
|
|
921
|
-
spec = new JavaScriptSerializer().Deserialize<LaunchSpec>(json);
|
|
922
|
-
if (spec == null || String.IsNullOrWhiteSpace(spec.command))
|
|
923
|
-
throw new ArgumentException("Launch payload is incomplete");
|
|
924
|
-
return Native.Run(
|
|
925
|
-
spec.command,
|
|
926
|
-
spec.args ?? new string[0],
|
|
927
|
-
spec.cpuSeconds,
|
|
928
|
-
spec.processMemoryBytes,
|
|
929
|
-
spec.activeProcessLimit,
|
|
930
|
-
spec.nodeIpcFd,
|
|
931
|
-
spec.detached,
|
|
932
|
-
spec.windowsHide,
|
|
933
|
-
spec.identityPath);
|
|
934
|
-
}
|
|
935
|
-
catch (Exception error)
|
|
936
|
-
{
|
|
937
|
-
if (!String.IsNullOrWhiteSpace(spec == null ? null : spec.identityPath))
|
|
938
|
-
{
|
|
939
|
-
try
|
|
940
|
-
{
|
|
941
|
-
string failure = new JavaScriptSerializer().Serialize(
|
|
942
|
-
new
|
|
943
|
-
{
|
|
944
|
-
error = error.ToString(),
|
|
945
|
-
helperPid =
|
|
946
|
-
System.Diagnostics.Process.GetCurrentProcess().Id
|
|
947
|
-
});
|
|
948
|
-
File.WriteAllText(
|
|
949
|
-
spec.identityPath,
|
|
950
|
-
failure,
|
|
951
|
-
new UTF8Encoding(false));
|
|
952
|
-
}
|
|
953
|
-
catch
|
|
954
|
-
{
|
|
955
|
-
// The original native failure remains authoritative.
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
Console.Error.WriteLine(
|
|
959
|
-
"CC_WINDOWS_SANDBOX_ERROR: " + error.Message);
|
|
960
|
-
return 125;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
'@
|
|
966
|
-
|
|
967
|
-
try {
|
|
968
|
-
if (-not (Test-Path -LiteralPath $CacheExecutable)) {
|
|
969
|
-
$temporaryExecutable = (
|
|
970
|
-
$CacheExecutable + "." + [Diagnostics.Process]::GetCurrentProcess().Id + ".exe"
|
|
971
|
-
)
|
|
972
|
-
Add-Type `
|
|
973
|
-
-TypeDefinition $nativeSource `
|
|
974
|
-
-Language CSharp `
|
|
975
|
-
-ReferencedAssemblies "System.Web.Extensions" `
|
|
976
|
-
-OutputAssembly $temporaryExecutable `
|
|
977
|
-
-OutputType ConsoleApplication
|
|
978
|
-
try {
|
|
979
|
-
[IO.File]::Move($temporaryExecutable, $CacheExecutable)
|
|
980
|
-
}
|
|
981
|
-
catch {
|
|
982
|
-
if (-not (Test-Path -LiteralPath $CacheExecutable)) {
|
|
983
|
-
throw
|
|
984
|
-
}
|
|
985
|
-
Remove-Item -LiteralPath $temporaryExecutable -Force -ErrorAction SilentlyContinue
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
if ($CompileOnly) {
|
|
989
|
-
exit 0
|
|
990
|
-
}
|
|
991
|
-
& $CacheExecutable @HelperArguments
|
|
992
|
-
exit $LASTEXITCODE
|
|
993
|
-
}
|
|
994
|
-
catch {
|
|
995
|
-
[Console]::Error.WriteLine(
|
|
996
|
-
"CC_WINDOWS_SANDBOX_ERROR: " + $_.Exception.Message
|
|
997
|
-
)
|
|
998
|
-
exit 125
|
|
999
|
-
}
|