job.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2010 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SANDBOX_WIN_SRC_JOB_H_
  5. #define SANDBOX_WIN_SRC_JOB_H_
  6. #include <stddef.h>
  7. #include "base/win/scoped_handle.h"
  8. namespace sandbox {
  9. enum class JobLevel;
  10. // Handles the creation of job objects based on a security profile.
  11. // Sample usage:
  12. // Job job;
  13. // job.Init(JobLevel::kLockdown, nullptr); //no job name
  14. // job.AssignProcessToJob(process_handle);
  15. class Job {
  16. public:
  17. Job();
  18. Job(const Job&) = delete;
  19. Job& operator=(const Job&) = delete;
  20. ~Job();
  21. // Initializes and creates the job object. The security of the job is based
  22. // on the security_level parameter.
  23. // job_name can be nullptr if the job is unnamed.
  24. // If the chosen profile has too many ui restrictions, you can disable some
  25. // by specifying them in the ui_exceptions parameters.
  26. // If the function succeeds, the return value is ERROR_SUCCESS. If the
  27. // function fails, the return value is the win32 error code corresponding to
  28. // the error.
  29. DWORD Init(JobLevel security_level,
  30. const wchar_t* job_name,
  31. DWORD ui_exceptions,
  32. size_t memory_limit);
  33. // Assigns the process referenced by process_handle to the job.
  34. // If the function succeeds, the return value is ERROR_SUCCESS. If the
  35. // function fails, the return value is the win32 error code corresponding to
  36. // the error.
  37. DWORD AssignProcessToJob(HANDLE process_handle);
  38. // Grants access to "handle" to the job. All processes in the job can
  39. // subsequently recognize and use the handle.
  40. // If the function succeeds, the return value is ERROR_SUCCESS. If the
  41. // function fails, the return value is the win32 error code corresponding to
  42. // the error.
  43. DWORD UserHandleGrantAccess(HANDLE handle);
  44. // True if the job has been initialized and has a valid handle.
  45. bool IsValid();
  46. // If the object is not yet initialized, returns nullptr.
  47. HANDLE GetHandle();
  48. // Updates the active process limit.
  49. DWORD SetActiveProcessLimit(DWORD processes);
  50. private:
  51. // Handle to the job referenced by the object.
  52. base::win::ScopedHandle job_handle_;
  53. };
  54. } // namespace sandbox
  55. #endif // SANDBOX_WIN_SRC_JOB_H_