target_services.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 2012 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_TARGET_SERVICES_H_
  5. #define SANDBOX_WIN_SRC_TARGET_SERVICES_H_
  6. #include "sandbox/win/src/sandbox.h"
  7. #include "sandbox/win/src/win_utils.h"
  8. namespace sandbox {
  9. class ProcessState {
  10. public:
  11. ProcessState();
  12. ProcessState(const ProcessState&) = delete;
  13. ProcessState& operator=(const ProcessState&) = delete;
  14. // Returns true if main has been called.
  15. bool InitCalled() const;
  16. // Returns true if LowerToken has been called.
  17. bool RevertedToSelf() const;
  18. // Returns true if Csrss is connected.
  19. bool IsCsrssConnected() const;
  20. // Set the current state.
  21. void SetInitCalled();
  22. void SetRevertedToSelf();
  23. void SetCsrssConnected(bool csrss_connected);
  24. private:
  25. enum class ProcessStateInternal { NONE = 0, INIT_CALLED, REVERTED_TO_SELF };
  26. ProcessStateInternal process_state_;
  27. bool csrss_connected_;
  28. };
  29. // This class is an implementation of the TargetServices.
  30. // Look in the documentation of sandbox::TargetServices for more info.
  31. // Do NOT add a destructor to this class without changing the implementation of
  32. // the factory method.
  33. class TargetServicesBase : public TargetServices {
  34. public:
  35. TargetServicesBase();
  36. TargetServicesBase(const TargetServicesBase&) = delete;
  37. TargetServicesBase& operator=(const TargetServicesBase&) = delete;
  38. // Public interface of TargetServices. See comments in sandbox.h.
  39. ResultCode Init() override;
  40. void LowerToken() override;
  41. ProcessState* GetState() override;
  42. SOCKET CreateBrokeredSocket(int af, int type, int protocol) override;
  43. // Factory method.
  44. static TargetServicesBase* GetInstance();
  45. // Sends a simple IPC Message that has a well-known answer. Returns true
  46. // if the IPC was successful and false otherwise. There are 2 versions of
  47. // this test: 1 and 2. The first one send a simple message while the
  48. // second one send a message with an in/out param.
  49. bool TestIPCPing(int version);
  50. private:
  51. ~TargetServicesBase() {}
  52. ProcessState process_state_;
  53. };
  54. } // namespace sandbox
  55. #endif // SANDBOX_WIN_SRC_TARGET_SERVICES_H_