/// <inheritdoc />
 public bool NotifyKextProcessFinished(long pipId, SandboxedProcessMacKext process)
 {
     if (m_pipProcesses.TryRemove(pipId, out var proc))
     {
         Contract.Assert(process == proc);
         return(true);
     }
     else
     {
         return(false);
     }
 }
        /// <inheritdoc />
        public bool NotifyKextPipStarted(FileAccessManifest fam, SandboxedProcessMacKext process)
        {
            Contract.Requires(process.Started);
            Contract.Requires(fam.PipId != 0);

            if (!m_pipProcesses.TryAdd(fam.PipId, process))
            {
                throw new BuildXLException($"Process with PidId {fam.PipId} already exists");
            }

            var setup = new FileAccessSetup()
            {
                DllNameX64 = string.Empty,
                DllNameX86 = string.Empty,
                ReportPath = process.ExecutableAbsolutePath, // piggybacking on ReportPath to pass full executable path
            };

            using (var wrapper = Pools.MemoryStreamPool.GetInstance())
            {
                var debugFlags = true;
                ArraySegment <byte> manifestBytes = fam.GetPayloadBytes(
                    setup,
                    wrapper.Instance,
                    timeoutMins: 10, // don't care because on Mac we don't kill the process from the Kext once it times out
                    debugFlagsMatch: ref debugFlags);

                Contract.Assert(manifestBytes.Offset == 0);

                var result = Sandbox.SendPipStarted(
                    processId: process.ProcessId,
                    pipId: fam.PipId,
                    famBytes: manifestBytes.Array,
                    famBytesLength: manifestBytes.Count,
                    info: m_kextConnectionInfo);

                return(result);
            }
        }
Exemple #3
0
        /// <inheritdoc />
        public bool NotifyKextPipStarted(FileAccessManifest fam, SandboxedProcessMacKext process)
        {
            Contract.Requires(process.Started);
            m_pipProcesses[fam.PipId] = process;

            var setup = new FileAccessSetup()
            {
                DllNameX64 = string.Empty,
                DllNameX86 = string.Empty,
                ReportPath = string.Empty
            };

            using (var wrapper = Pools.MemoryStreamPool.GetInstance())
            {
                var debugFlags = true;
                ArraySegment <byte> manifestBytes = fam.GetPayloadBytes(
                    setup,
                    wrapper.Instance,
                    timeoutMins: 10, // don't care because on Mac we don't kill the process from the Kext once it times out
                    debugFlagsMatch: ref debugFlags);

                var payloadHandle = GCHandle.Alloc(manifestBytes.Array, GCHandleType.Pinned);
                var result        = Sandbox.SendPipStarted(
                    processId: process.ProcessId,
                    pipId: fam.PipId,
                    famBytes: IntPtr.Add(payloadHandle.AddrOfPinnedObject(), manifestBytes.Offset),
                    famBytesLength: manifestBytes.Count);

                if (payloadHandle.IsAllocated)
                {
                    payloadHandle.Free();
                }

                return(result);
            }
        }