예제 #1
0
 /// <remarks>
 /// This constructor is never used in this project, but there exist external projects that
 /// compile against this assembly and already depend on this constructor.
 /// </remarks>
 public SandboxedProcessInfo(
     [CanBeNull] ISandboxedProcessFileStorage fileStorage,
     string fileName,
     bool disableConHostSharing,
     bool testRetries = false,
     LoggingContext loggingContext = null,
     IDetoursEventListener detoursEventListener = null,
     ISandboxConnection sandboxConnection       = null,
     bool createJobObjectForCurrentProcess      = true)
     : this(
         new PathTable(),
         fileStorage,
         fileName,
         disableConHostSharing,
         loggingContext ?? new LoggingContext("ExternalComponent"),
         testRetries,
         detoursEventListener,
         sandboxConnection,
         createJobObjectForCurrentProcess : createJobObjectForCurrentProcess)
 {
 }
예제 #2
0
        /// <summary>
        /// Creates instance
        /// </summary>
        public SandboxedProcessInfo(
            PathTable pathTable,
            [CanBeNull] ISandboxedProcessFileStorage fileStorage,
            string fileName,
            FileAccessManifest fileAccessManifest,
            bool disableConHostSharing,
            ContainerConfiguration containerConfiguration,
            LoggingContext loggingContext,
            bool testRetries = false,
            IDetoursEventListener detoursEventListener = null,
            ISandboxConnection sandboxConnection       = null,
            SidebandWriter sidebandWriter         = null,
            bool createJobObjectForCurrentProcess = true,
            ISandboxFileSystemView fileSystemView = null,
            SandboxedProcessResourceMonitoringConfig monitoringConfig = null)
        {
            Contract.RequiresNotNull(pathTable);
            Contract.RequiresNotNull(fileName);

            PathTable             = pathTable;
            FileAccessManifest    = fileAccessManifest;
            FileStorage           = fileStorage;
            FileName              = fileName;
            DisableConHostSharing = disableConHostSharing;

            // This should be set for testing purposes only.
            TestRetries = testRetries;

            NestedProcessTerminationTimeout = DefaultNestedProcessTerminationTimeout;
            LoggingContext                   = loggingContext;
            DetoursEventListener             = detoursEventListener;
            SandboxConnection                = sandboxConnection;
            ContainerConfiguration           = containerConfiguration;
            SidebandWriter                   = sidebandWriter;
            CreateJobObjectForCurrentProcess = createJobObjectForCurrentProcess;
            FileSystemView                   = fileSystemView;
            MonitoringConfig                 = monitoringConfig;
        }
예제 #3
0
        public SandboxedProcessReports(
            FileAccessManifest manifest,
            PathTable pathTable,
            long pipSemiStableHash,
            string pipDescription,
            LoggingContext loggingContext,
            IDetoursEventListener detoursEventListener = null)
        {
            Contract.Requires(manifest != null);
            Contract.Requires(pathTable != null);
            Contract.Requires(pipDescription != null);

            PipSemiStableHash = pipSemiStableHash;
            PipDescription = pipDescription;
            m_pathTable = pathTable;
            FileAccesses = manifest.ReportFileAccesses ? new HashSet<ReportedFileAccess>() : null;
            FileUnexpectedAccesses = new HashSet<ReportedFileAccess>();
            m_manifest = manifest;
            m_detoursEventListener = detoursEventListener;

            // For tests we need the StaticContext
            m_loggingContext = loggingContext ?? BuildXL.Utilities.Tracing.Events.StaticContext;
        }
예제 #4
0
        /// <remarks>
        /// IMPORTANT: For memory efficiency reasons don't keep a reference to <paramref name="info"/>
        ///            or its  <see cref="SandboxedProcessInfo.FileAccessManifest"/> property
        ///            (at least not after the process has been started)
        /// </remarks>
        public UnsandboxedProcess(SandboxedProcessInfo info)
        {
            Contract.Requires(info != null);

            Started                  = false;
            PathTable                = info.PathTable;
            LoggingContext           = info.LoggingContext;
            PipDescription           = info.PipDescription;
            PipSemiStableHash        = info.PipSemiStableHash;
            TimeoutDumpDirectory     = info.TimeoutDumpDirectory;
            ShouldReportFileAccesses = info.FileAccessManifest?.ReportFileAccesses == true;
            DetoursListener          = info.DetoursEventListener;

            info.Timeout ??= s_defaultProcessTimeout;

            m_output = new SandboxedProcessOutputBuilder(
                info.StandardOutputEncoding ?? Console.OutputEncoding,
                info.MaxLengthInMemory,
                info.FileStorage,
                SandboxedProcessFile.StandardOutput,
                info.StandardOutputObserver);

            m_error = new SandboxedProcessOutputBuilder(
                info.StandardErrorEncoding ?? Console.OutputEncoding,
                info.MaxLengthInMemory,
                info.FileStorage,
                SandboxedProcessFile.StandardError,
                info.StandardErrorObserver);

            m_processExecutor = new AsyncProcessExecutor(
                CreateProcess(info),
                info.Timeout ?? s_defaultProcessTimeout,
                line => FeedStdOut(m_output, line),
                line => FeedStdErr(m_error, line),
                info.Provenance,
                msg => LogProcessState(msg));
        }
예제 #5
0
        public SandboxedProcessReports(
            FileAccessManifest manifest,
            PathTable pathTable,
            long pipSemiStableHash,
            string pipDescription,
            LoggingContext loggingContext,
            [CanBeNull] IDetoursEventListener detoursEventListener,
            [CanBeNull] SidebandWriter sharedOpaqueOutputLogger)
        {
            Contract.RequiresNotNull(manifest);
            Contract.RequiresNotNull(pathTable);
            Contract.RequiresNotNull(pipDescription);
            Contract.RequiresNotNull(loggingContext);

            PipSemiStableHash          = pipSemiStableHash;
            PipDescription             = pipDescription;
            m_pathTable                = pathTable;
            FileAccesses               = manifest.ReportFileAccesses ? new HashSet <ReportedFileAccess>() : null;
            FileUnexpectedAccesses     = new HashSet <ReportedFileAccess>();
            m_manifest                 = manifest;
            m_detoursEventListener     = detoursEventListener;
            m_sharedOpaqueOutputLogger = sharedOpaqueOutputLogger;
            m_loggingContext           = loggingContext;
        }
예제 #6
0
        /// <nodoc />
        public static SandboxedProcessInfo Deserialize(Stream stream, LoggingContext loggingContext, IDetoursEventListener detoursEventListener)
        {
            using (var reader = new BuildXLReader(false, stream, true))
            {
                string           arguments             = reader.ReadNullableString();
                string           commandLine           = reader.ReadNullableString();
                bool             disableConHostSharing = reader.ReadBoolean();
                string           fileName = reader.ReadNullableString();
                Encoding         standardInputEncoding  = reader.ReadNullable(r => r.ReadEncoding());
                Encoding         standardOutputEncoding = reader.ReadNullable(r => r.ReadEncoding());
                Encoding         standardErrorEncoding  = reader.ReadNullable(r => r.ReadEncoding());
                string           workingDirectory       = reader.ReadNullableString();
                IBuildParameters buildParameters        = null;
                var envVars = reader.ReadNullable(r => r.ReadReadOnlyList(r2 => new KeyValuePair <string, string>(r2.ReadString(), r2.ReadString())));
                if (envVars != null)
                {
                    buildParameters = BuildParameters.GetFactory().PopulateFromDictionary(envVars.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
                }

                string[]    allowedSurvivingChildNames = reader.ReadNullable(r => r.ReadReadOnlyList(r2 => r2.ReadString()))?.ToArray();
                int         maxLengthInMemory          = reader.ReadInt32();
                TimeSpan?   timeout = reader.ReadNullableStruct(r => r.ReadTimeSpan());
                TimeSpan    nestedProcessTerminationTimeout = reader.ReadTimeSpan();
                long        pipSemiStableHash    = reader.ReadInt64();
                string      timeoutDumpDirectory = reader.ReadNullableString();
                SandboxKind sandboxKind          = (SandboxKind)reader.ReadByte();
                string      pipDescription       = reader.ReadNullableString();
                SandboxedProcessStandardFiles sandboxedProcessStandardFiles = SandboxedProcessStandardFiles.Deserialize(reader);
                StandardInputInfo             standardInputSourceInfo       = reader.ReadNullable(r => StandardInputInfo.Deserialize(r));
                SandboxObserverDescriptor     standardObserverDescriptor    = reader.ReadNullable(r => SandboxObserverDescriptor.Deserialize(r));

                FileAccessManifest fam = reader.ReadNullable(r => FileAccessManifest.Deserialize(stream));

                return(new SandboxedProcessInfo(
                           new PathTable(),
                           new StandardFileStorage(sandboxedProcessStandardFiles),
                           fileName,
                           fam,
                           disableConHostSharing,
                           // TODO: serialize/deserialize container configuration.
                           containerConfiguration: ContainerConfiguration.DisabledIsolation,
                           loggingContext: loggingContext,
                           detoursEventListener: detoursEventListener)
                {
                    m_arguments = arguments,
                    m_commandLine = commandLine,
                    StandardInputEncoding = standardInputEncoding,
                    StandardOutputEncoding = standardOutputEncoding,
                    StandardErrorEncoding = standardErrorEncoding,
                    WorkingDirectory = workingDirectory,
                    EnvironmentVariables = buildParameters,
                    AllowedSurvivingChildProcessNames = allowedSurvivingChildNames,
                    MaxLengthInMemory = maxLengthInMemory,
                    Timeout = timeout,
                    NestedProcessTerminationTimeout = nestedProcessTerminationTimeout,
                    PipSemiStableHash = pipSemiStableHash,
                    TimeoutDumpDirectory = timeoutDumpDirectory,
                    SandboxKind = sandboxKind,
                    PipDescription = pipDescription,
                    SandboxedProcessStandardFiles = sandboxedProcessStandardFiles,
                    StandardInputSourceInfo = standardInputSourceInfo,
                    StandardObserverDescriptor = standardObserverDescriptor
                });
            }
        }