1 // Copyright (c) 2006-2008 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 5 #include "sandbox/win/src/sandbox.h" 6 7 #include <windows.h> 8 9 #include "sandbox/win/src/broker_services.h" 10 #include "sandbox/win/src/sandbox_factory.h" 11 #include "sandbox/win/src/target_services.h" 12 13 namespace sandbox { 14 // The section for IPC and policy. 15 SANDBOX_INTERCEPT HANDLE g_shared_section; 16 static bool s_is_broker = false; 17 18 // GetBrokerServices: the current implementation relies on a shared section 19 // that is created by the broker and opened by the target. GetBrokerServices()20BrokerServices* SandboxFactory::GetBrokerServices() { 21 // Can't be the broker if the shared section is open. 22 if (g_shared_section) 23 return nullptr; 24 // If the shared section does not exist we are the broker, then create 25 // the broker object. 26 s_is_broker = true; 27 return BrokerServicesBase::GetInstance(); 28 } 29 30 // GetTargetServices implementation must follow the same technique as the 31 // GetBrokerServices, but in this case the logic is the opposite. GetTargetServices()32TargetServices* SandboxFactory::GetTargetServices() { 33 // Can't be the target if the section handle is not valid. 34 if (!g_shared_section) 35 return nullptr; 36 // We are the target 37 s_is_broker = false; 38 // Creates and returns the target services implementation. 39 return TargetServicesBase::GetInstance(); 40 } 41 42 } // namespace sandbox 43 44 // Allows querying for whether the current process has been sandboxed. IsSandboxedProcess()45extern "C" bool __declspec(dllexport) IsSandboxedProcess() { 46 return !!sandbox::g_shared_section; 47 } 48