private void SetJobNotificationLimits(NativeMethods.JobObjectNotificationLimitInformation notificationLimit) { using (var allocation = SafeAllocation.Create(notificationLimit)) { if (!NativeMethods.SetInformationJobObject(handle, NativeMethods.JobObjectInfoClass.NotificationLimitInformation, allocation.DangerousGetHandle(), allocation.Size)) { throw Win32LastError("Unable to set limit violation information"); } } }
public virtual int GetJobCpuLimit() { using (var allocation = SafeAllocation.Create <NativeMethods.JobObjectCpuRateControlInformation>()) { if (!NativeMethods.QueryInformationJobObject(handle, NativeMethods.JobObjectInfoClass.CpuRateControlInformation, allocation.DangerousGetHandle(), allocation.Size, IntPtr.Zero)) { throw Win32LastError("Unable to query Cpu rate information"); } return((int)allocation.ToStructure().CpuRate); } }
public NativeMethods.JobObjectLimitViolationInformation GetLimitViolationInformation() { using (var allocation = SafeAllocation.Create <NativeMethods.JobObjectLimitViolationInformation>()) { if (!NativeMethods.QueryInformationJobObject(handle, NativeMethods.JobObjectInfoClass.LimitViolationInformation, allocation.DangerousGetHandle(), allocation.Size, IntPtr.Zero)) { throw Win32LastError("Unable to query limit violation information"); } return(allocation.ToStructure()); } }
private void SetUIRestrictions(NativeMethods.UIRestrictions restrictionsFlag) { var restrictions = new NativeMethods.JobObjectUIRestrictions { UIRestrictionsClass = restrictionsFlag }; using (var allocation = SafeAllocation.Create(restrictions)) { if (!NativeMethods.SetInformationJobObject(handle, NativeMethods.JobObjectInfoClass.BasicUIRestrictions, allocation.DangerousGetHandle(), allocation.Size)) { throw new Exception(string.Format("Unable to set information. Error: {0}", Marshal.GetLastWin32Error())); } } }
private ACCESS_MASK AccessCheck(SafeAuthzContextHandle userClientCtxt, RawSecurityDescriptor descriptor) { ACCESS_MASK accessGranted; // Prepare the Access Check request var request = new NativeMethods.AUTHZ_ACCESS_REQUEST(); request.DesiredAccess = ACCESS_MASK.MAXIMUM_ALLOWED; request.PrincipalSelfSid = null; request.ObjectTypeList = IntPtr.Zero; request.ObjectTypeListLength = 0; request.OptionalArguments = IntPtr.Zero; using (var grantedAccessBuffer = SafeAllocation.Create <ACCESS_MASK>()) using (var errorBuffer = SafeAllocation.Create <uint>()) { // Prepare the access check reply var reply = new NativeMethods.AUTHZ_ACCESS_REPLY(); reply.ResultListLength = 1; reply.SaclEvaluationResults = IntPtr.Zero; reply.GrantedAccessMask = grantedAccessBuffer.DangerousGetHandle(); reply.Error = errorBuffer.DangerousGetHandle(); var rawSD = new byte[descriptor.BinaryLength]; descriptor.GetBinaryForm(rawSD, 0); if (!NativeMethods.AuthzAccessCheck( NativeMethods.AuthzACFlags.None, userClientCtxt, ref request, IntPtr.Zero, rawSD, null, 0, ref reply, IntPtr.Zero)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } accessGranted = grantedAccessBuffer.ToStructure(); } return(accessGranted); }
public virtual void SetJobCpuLimit(int cpuWeight) { if (cpuWeight < 1 || cpuWeight > 9) { throw new ArgumentOutOfRangeException("cpuWeight", cpuWeight, "CPU Limit must be between 1 and 9"); } var cpuRateInfo = new NativeMethods.JobObjectCpuRateControlInformation { ControlFlags = (UInt32)(NativeMethods.JobObjectCpuRateControl.Enable | NativeMethods.JobObjectCpuRateControl.WeightBased), Weight = (uint)cpuWeight, }; using (var allocation = SafeAllocation.Create <NativeMethods.JobObjectCpuRateControlInformation>(cpuRateInfo)) { if (!NativeMethods.SetInformationJobObject(handle, NativeMethods.JobObjectInfoClass.CpuRateControlInformation, allocation.DangerousGetHandle(), allocation.Size)) { throw Win32LastError("Unable to query Cpu rate information"); } } }