Esempio n. 1
0
        /// <summary>
        /// Creates a new <see cref="JobObject"/> instance.
        /// </summary>
        /// <param name="Limits">The <see cref="JobLimits"/> to apply to the new <see cref="JobObject"/>.</param>
        /// <param name="Notifications">The <see cref="JobNotifications"/> to apply to the new <see cref="JobObject"/>.</param>
        public JobObject(JobLimits?Limits = null, JobNotifications?Notifications = null)
        {
            try
            {
                // get the completion port reference..
                _completionPort = JobObjectCompletionPort.GetCompletionPort();

                // create the handle..
                _handle = Interop.Kernel32.CreateJobObject(IntPtr.Zero, null);
                if ((_handle == null) || (_handle.IsInvalid))
                {
                    throw Errors.Win32Error();
                }

                // join the handle to the completion port..
                AssociateWithPort();

                // configure limits..
                if (Limits.HasValue)
                {
                    SetLimits(Limits.Value);
                }
                if ((Notifications.HasValue) && (_jobsLimitViolationSupported))
                {
                    SetNotifications(Notifications.Value);
                }
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Esempio n. 2
0
 internal static extern bool DuplicateHandle(
     IntPtr hSourceProcessHandle,
     SafeJobObjectHandle hSourceHandle,
     IntPtr hTargetProcess,
     out SafeJobObjectHandle targetHandle,
     int dwDesiredAccess,
     bool bInheritHandle,
     int dwOptions
     );
Esempio n. 3
0
        static JobObjectInfo()
        {
            // create a JobObject and determine what options are supported on this OS..
            SafeJobObjectHandle jobHandle = null;

            try
            {
                jobHandle = Interop.Kernel32.CreateJobObject(IntPtr.Zero, null);
                if (jobHandle.IsInvalid)
                {
                    return;
                }

                _jobsSupported = true;

                // notification limit
                // notification limit 2
                // net rate control
                // violation limit
                // violation limit 2
                // job object group info
                // cpu rate control
                // group information ex

                IntPtr memoryPtr = IntPtr.Zero;
                try
                {
                    int memorySize = 1024;
                    memoryPtr = Marshal.AllocHGlobal(memorySize);

                    // ask for specific structures to determine the level of support..
                    _jobsGroupSupported           = IsSupported(jobHandle, Interop.Kernel32.JobObjectInformationClass.GroupInformation, memoryPtr, memorySize);
                    _jobsGroupExSupported         = IsSupported(jobHandle, Interop.Kernel32.JobObjectInformationClass.GroupInformationEx, memoryPtr, memorySize);
                    _jobsLimitViolationSupported  = IsSupported(jobHandle, Interop.Kernel32.JobObjectInformationClass.LimitViolationInformation, memoryPtr, memorySize);
                    _jobsLimitViolation2Supported = IsSupported(jobHandle, Interop.Kernel32.JobObjectInformationClass.LimitViolationInformation2, memoryPtr, memorySize);
                }
                finally
                {
                    if (memoryPtr != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal(memoryPtr);
                    }
                }
            }
            finally
            {
                jobHandle?.Dispose();
            }
        }
        public WindowsChildProcessState(
            int processId,
            SafeProcessHandle processHandle,
            SafeJobObjectHandle jobObjectHandle,
            InputWriterOnlyPseudoConsole?pseudoConsole,
            bool allowSignal)
        {
            Debug.Assert(!(allowSignal && pseudoConsole is null));

            _processId        = processId;
            _processHandle    = processHandle;
            _jobObjectHandle  = jobObjectHandle;
            _pseudoConsole    = pseudoConsole;
            _allowSignal      = allowSignal;
            _exitedWaitHandle = new WindowsProcessWaitHandle(_processHandle);
        }
Esempio n. 5
0
 internal static extern bool QueryInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, IntPtr lpJobObjectInfo, int cbJobObjectInfoLength, out int lpReturnLength);
Esempio n. 6
0
 internal static extern bool QueryInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [Out] out JOBOBJECT_LIMIT_VIOLATION_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength, IntPtr lpReturnLength);
Esempio n. 7
0
 internal static extern bool QueryInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [Out] out JOBOBJECT_BASIC_UI_RESTRICTIONS lpJobObjectInfo, int cbJobObjectInfoLength, IntPtr lpReturnLength);
Esempio n. 8
0
 internal static extern bool QueryInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [Out] out JOBOBJECT_BASIC_AND_IO_ACCOUNTING_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength, IntPtr lpReturnLength);
Esempio n. 9
0
 internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_NOTIFICATION_LIMIT_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength);
Esempio n. 10
0
 internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_CPU_RATE_CONTROL_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength);
Esempio n. 11
0
 public unsafe JobObject(string name = null)
 {
     mHandle = Kernel32.CreateJobObjectW(null, name);
 }
Esempio n. 12
0
 internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_END_OF_JOB_TIME_INFORMATION lpJobObjectInfo, int cbJobObjectInfoLength);
Esempio n. 13
0
 internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_ASSOCIATE_COMPLETION_PORT lpJobObjectInfo, int cbJobObjectInfoLength);
Esempio n. 14
0
 internal static extern bool AssignProcessToJobObject(SafeJobObjectHandle hJob, SafeProcessHandle hProcess);
Esempio n. 15
0
 internal static extern bool SetInformationJobObject(SafeJobObjectHandle hJob, JobObjectInformationClass JobObjectInfoClass, [In] ref JOBOBJECT_BASIC_UI_RESTRICTIONS lpJobObjectInfo, int cbJobObjectInfoLength);
Esempio n. 16
0
 internal static extern bool TerminateJobObject(SafeJobObjectHandle hJob, int uExitCode);
Esempio n. 17
0
 internal static extern bool UserHandleGrantAccess(IntPtr hUserHandle, SafeJobObjectHandle hJob, BOOL bGrant);