1 // Copyright 2014 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 #ifndef MOJO_EDK_SYSTEM_MAPPING_TABLE_H_ 6 #define MOJO_EDK_SYSTEM_MAPPING_TABLE_H_ 7 8 #include <stdint.h> 9 10 #include <memory> 11 #include <vector> 12 13 #include "base/containers/hash_tables.h" 14 #include "base/macros.h" 15 #include "mojo/edk/system/system_impl_export.h" 16 #include "mojo/public/c/system/types.h" 17 18 namespace mojo { 19 20 namespace edk { 21 class Core; 22 class PlatformSharedBufferMapping; 23 24 // Test-only function (defined/used in embedder/test_embedder.cc). Declared here 25 // so it can be friended. 26 namespace internal { 27 bool ShutdownCheckNoLeaks(Core*); 28 } 29 30 // This class provides the (global) table of memory mappings (owned by |Core|), 31 // which maps mapping base addresses to |PlatformSharedBufferMapping|s. 32 // 33 // This class is NOT thread-safe; locking is left to |Core|. 34 class MOJO_SYSTEM_IMPL_EXPORT MappingTable { 35 public: 36 MappingTable(); 37 ~MappingTable(); 38 39 // Tries to add a mapping. (Takes ownership of the mapping in all cases; on 40 // failure, it will be destroyed.) 41 MojoResult AddMapping(std::unique_ptr<PlatformSharedBufferMapping> mapping); 42 MojoResult RemoveMapping(void* address); 43 44 private: 45 friend bool internal::ShutdownCheckNoLeaks(Core*); 46 47 using AddressToMappingMap = 48 base::hash_map<void*, PlatformSharedBufferMapping*>; 49 AddressToMappingMap address_to_mapping_map_; 50 51 DISALLOW_COPY_AND_ASSIGN(MappingTable); 52 }; 53 54 } // namespace edk 55 } // namespace mojo 56 57 #endif // MOJO_EDK_SYSTEM_MAPPING_TABLE_H_ 58