jobobject.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package winapi
  2. import (
  3. "golang.org/x/sys/windows"
  4. )
  5. // Messages that can be received from an assigned io completion port.
  6. // https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_associate_completion_port
  7. const (
  8. JOB_OBJECT_MSG_END_OF_JOB_TIME = 1
  9. JOB_OBJECT_MSG_END_OF_PROCESS_TIME = 2
  10. JOB_OBJECT_MSG_ACTIVE_PROCESS_LIMIT = 3
  11. JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO = 4
  12. JOB_OBJECT_MSG_NEW_PROCESS = 6
  13. JOB_OBJECT_MSG_EXIT_PROCESS = 7
  14. JOB_OBJECT_MSG_ABNORMAL_EXIT_PROCESS = 8
  15. JOB_OBJECT_MSG_PROCESS_MEMORY_LIMIT = 9
  16. JOB_OBJECT_MSG_JOB_MEMORY_LIMIT = 10
  17. JOB_OBJECT_MSG_NOTIFICATION_LIMIT = 11
  18. )
  19. // IO limit flags
  20. //
  21. // https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/ns-jobapi2-jobobject_io_rate_control_information
  22. const JOB_OBJECT_IO_RATE_CONTROL_ENABLE = 0x1
  23. // https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information
  24. const (
  25. JOB_OBJECT_CPU_RATE_CONTROL_ENABLE = 1 << iota
  26. JOB_OBJECT_CPU_RATE_CONTROL_WEIGHT_BASED
  27. JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP
  28. JOB_OBJECT_CPU_RATE_CONTROL_NOTIFY
  29. JOB_OBJECT_CPU_RATE_CONTROL_MIN_MAX_RATE
  30. )
  31. // JobObjectInformationClass values. Used for a call to QueryInformationJobObject
  32. //
  33. // https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/nf-jobapi2-queryinformationjobobject
  34. const (
  35. JobObjectBasicAccountingInformation uint32 = 1
  36. JobObjectBasicProcessIdList uint32 = 3
  37. JobObjectBasicAndIoAccountingInformation uint32 = 8
  38. JobObjectLimitViolationInformation uint32 = 13
  39. JobObjectNotificationLimitInformation2 uint32 = 33
  40. )
  41. // https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_limit_information
  42. type JOBOBJECT_BASIC_LIMIT_INFORMATION struct {
  43. PerProcessUserTimeLimit int64
  44. PerJobUserTimeLimit int64
  45. LimitFlags uint32
  46. MinimumWorkingSetSize uintptr
  47. MaximumWorkingSetSize uintptr
  48. ActiveProcessLimit uint32
  49. Affinity uintptr
  50. PriorityClass uint32
  51. SchedulingClass uint32
  52. }
  53. // https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_cpu_rate_control_information
  54. type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION struct {
  55. ControlFlags uint32
  56. Rate uint32
  57. }
  58. // https://docs.microsoft.com/en-us/windows/win32/api/jobapi2/ns-jobapi2-jobobject_io_rate_control_information
  59. type JOBOBJECT_IO_RATE_CONTROL_INFORMATION struct {
  60. MaxIops int64
  61. MaxBandwidth int64
  62. ReservationIops int64
  63. BaseIOSize uint32
  64. VolumeName string
  65. ControlFlags uint32
  66. }
  67. // https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_basic_process_id_list
  68. type JOBOBJECT_BASIC_PROCESS_ID_LIST struct {
  69. NumberOfAssignedProcesses uint32
  70. NumberOfProcessIdsInList uint32
  71. ProcessIdList [1]uintptr
  72. }
  73. // https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_associate_completion_port
  74. type JOBOBJECT_ASSOCIATE_COMPLETION_PORT struct {
  75. CompletionKey uintptr
  76. CompletionPort windows.Handle
  77. }
  78. // BOOL IsProcessInJob(
  79. // HANDLE ProcessHandle,
  80. // HANDLE JobHandle,
  81. // PBOOL Result
  82. // );
  83. //
  84. //sys IsProcessInJob(procHandle windows.Handle, jobHandle windows.Handle, result *bool) (err error) = kernel32.IsProcessInJob
  85. // BOOL QueryInformationJobObject(
  86. // HANDLE hJob,
  87. // JOBOBJECTINFOCLASS JobObjectInformationClass,
  88. // LPVOID lpJobObjectInformation,
  89. // DWORD cbJobObjectInformationLength,
  90. // LPDWORD lpReturnLength
  91. // );
  92. //
  93. //sys QueryInformationJobObject(jobHandle windows.Handle, infoClass uint32, jobObjectInfo uintptr, jobObjectInformationLength uint32, lpReturnLength *uint32) (err error) = kernel32.QueryInformationJobObject
  94. // HANDLE OpenJobObjectW(
  95. // DWORD dwDesiredAccess,
  96. // BOOL bInheritHandle,
  97. // LPCWSTR lpName
  98. // );
  99. //
  100. //sys OpenJobObject(desiredAccess uint32, inheritHandle bool, lpName *uint16) (handle windows.Handle, err error) = kernel32.OpenJobObjectW
  101. // DWORD SetIoRateControlInformationJobObject(
  102. // HANDLE hJob,
  103. // JOBOBJECT_IO_RATE_CONTROL_INFORMATION *IoRateControlInfo
  104. // );
  105. //
  106. //sys SetIoRateControlInformationJobObject(jobHandle windows.Handle, ioRateControlInfo *JOBOBJECT_IO_RATE_CONTROL_INFORMATION) (ret uint32, err error) = kernel32.SetIoRateControlInformationJobObject