sandbox.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2017 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_POLICY_SANDBOX_H_
  5. #define SANDBOX_POLICY_SANDBOX_H_
  6. #include "build/build_config.h"
  7. #include "sandbox/policy/export.h"
  8. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  9. #include "sandbox/policy/linux/sandbox_linux.h"
  10. #endif
  11. namespace sandbox {
  12. namespace mojom {
  13. enum class Sandbox;
  14. } // namespace mojom
  15. struct SandboxInterfaceInfo;
  16. } // namespace sandbox
  17. namespace sandbox {
  18. namespace policy {
  19. // Interface to the service manager sandboxes across the various platforms.
  20. //
  21. // Ideally, this API would abstract away the platform differences, but there
  22. // are some major OS differences that shape this interface, including:
  23. // * Whether the sandboxing is performed by the launcher (Windows, Fuchsia
  24. // someday) or by the launchee (Linux, Mac).
  25. // * The means of specifying the additional resources that are permitted.
  26. // * The need to "warmup" other resources before engaing the sandbox.
  27. class SANDBOX_POLICY_EXPORT Sandbox {
  28. public:
  29. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  30. static bool Initialize(sandbox::mojom::Sandbox sandbox_type,
  31. SandboxLinux::PreSandboxHook hook,
  32. const SandboxLinux::Options& options);
  33. #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  34. #if BUILDFLAG(IS_WIN)
  35. static bool Initialize(sandbox::mojom::Sandbox sandbox_type,
  36. SandboxInterfaceInfo* sandbox_info);
  37. #endif // BUILDFLAG(IS_WIN)
  38. // Returns true if the current process is running with a sandbox, and false
  39. // if the process is not sandboxed. This should be used to assert that code is
  40. // not running at high-privilege (e.g. in the browser process):
  41. //
  42. // DCHECK(Sandbox::IsProcessSandboxed());
  43. //
  44. // The definition of what constitutes a sandbox, and the relative strength of
  45. // the restrictions placed on the process, and a per-platform implementation
  46. // detail.
  47. //
  48. // Except if the process is the browser, if the process is running with the
  49. // --no-sandbox flag, this unconditionally returns true.
  50. static bool IsProcessSandboxed();
  51. };
  52. } // namespace policy
  53. } // namespace sandbox
  54. #endif // SANDBOX_POLICY_SANDBOX_H_