1 // Copyright 2019 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_MEMORY_SHARED_MEMORY_HOOKS_H_ 6 #define BASE_MEMORY_SHARED_MEMORY_HOOKS_H_ 7 8 #include "base/memory/read_only_shared_memory_region.h" 9 #include "base/memory/unsafe_shared_memory_region.h" 10 #include "base/memory/writable_shared_memory_region.h" 11 12 namespace mojo { 13 class SharedMemoryUtils; 14 namespace core::ipcz_driver { 15 class BaseSharedMemoryService; 16 } 17 } // namespace mojo 18 19 namespace base { 20 21 class SharedMemoryHooks { 22 public: 23 SharedMemoryHooks() = delete; 24 25 private: 26 friend class SharedMemoryHooksTest; 27 friend mojo::SharedMemoryUtils; 28 friend class mojo::core::ipcz_driver::BaseSharedMemoryService; 29 30 // Allows shared memory region creation to be hooked. Useful for sandboxed 31 // processes that are restricted from invoking the platform APIs directly. 32 // Intentionally private so callers need to be explicitly friended. SetCreateHooks(ReadOnlySharedMemoryRegion::CreateFunction * read_only_hook,UnsafeSharedMemoryRegion::CreateFunction * unsafe_hook,WritableSharedMemoryRegion::CreateFunction * writable_hook)33 static void SetCreateHooks( 34 ReadOnlySharedMemoryRegion::CreateFunction* read_only_hook, 35 UnsafeSharedMemoryRegion::CreateFunction* unsafe_hook, 36 WritableSharedMemoryRegion::CreateFunction* writable_hook) { 37 ReadOnlySharedMemoryRegion::set_create_hook(read_only_hook); 38 UnsafeSharedMemoryRegion::set_create_hook(unsafe_hook); 39 WritableSharedMemoryRegion::set_create_hook(writable_hook); 40 } 41 }; 42 43 } // namespace base 44 45 #endif // BASE_MEMORY_SHARED_MEMORY_HOOKS_H_ 46