michael@0: // Copyright (c) 2010 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef SANDBOX_SRC_SIDESTEP_RESOLVER_H__ michael@0: #define SANDBOX_SRC_SIDESTEP_RESOLVER_H__ michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "sandbox/win/src/nt_internals.h" michael@0: #include "sandbox/win/src/resolver.h" michael@0: michael@0: namespace sandbox { michael@0: michael@0: // This is the concrete resolver used to perform sidestep interceptions. michael@0: class SidestepResolverThunk : public ResolverThunk { michael@0: public: michael@0: SidestepResolverThunk() {} michael@0: virtual ~SidestepResolverThunk() {} michael@0: michael@0: // Implementation of Resolver::Setup. michael@0: virtual NTSTATUS Setup(const void* target_module, michael@0: const void* interceptor_module, michael@0: const char* target_name, michael@0: const char* interceptor_name, michael@0: const void* interceptor_entry_point, michael@0: void* thunk_storage, michael@0: size_t storage_bytes, michael@0: size_t* storage_used); michael@0: michael@0: // Implementation of Resolver::GetThunkSize. michael@0: virtual size_t GetThunkSize() const; michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(SidestepResolverThunk); michael@0: }; michael@0: michael@0: // This is the concrete resolver used to perform smart sidestep interceptions. michael@0: // This means basically a sidestep interception that skips the interceptor when michael@0: // the caller resides on the same dll being intercepted. It is intended as michael@0: // a helper only, because that determination is not infallible. michael@0: class SmartSidestepResolverThunk : public SidestepResolverThunk { michael@0: public: michael@0: SmartSidestepResolverThunk() {} michael@0: virtual ~SmartSidestepResolverThunk() {} michael@0: michael@0: // Implementation of Resolver::Setup. michael@0: virtual NTSTATUS Setup(const void* target_module, michael@0: const void* interceptor_module, michael@0: const char* target_name, michael@0: const char* interceptor_name, michael@0: const void* interceptor_entry_point, michael@0: void* thunk_storage, michael@0: size_t storage_bytes, michael@0: size_t* storage_used); michael@0: michael@0: // Implementation of Resolver::GetThunkSize. michael@0: virtual size_t GetThunkSize() const; michael@0: michael@0: private: michael@0: // Performs the actual call to the interceptor if the conditions are correct michael@0: // (as determined by IsInternalCall). michael@0: static void SmartStub(); michael@0: michael@0: // Returns true if return_address is inside the module loaded at base. michael@0: static bool IsInternalCall(const void* base, void* return_address); michael@0: michael@0: DISALLOW_COPY_AND_ASSIGN(SmartSidestepResolverThunk); michael@0: }; michael@0: michael@0: } // namespace sandbox michael@0: michael@0: michael@0: #endif // SANDBOX_SRC_SIDESTEP_RESOLVER_H__