1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SRC_TRACING_IPC_SHARED_MEMORY_WINDOWS_H_ 18 #define SRC_TRACING_IPC_SHARED_MEMORY_WINDOWS_H_ 19 20 #include "perfetto/base/build_config.h" 21 22 #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) 23 24 #include "perfetto/base/build_config.h" 25 #include "perfetto/ext/base/scoped_file.h" 26 #include "perfetto/ext/tracing/core/shared_memory.h" 27 28 namespace perfetto { 29 30 // Implements the SharedMemory and its factory for the Windows IPC transport. 31 // This used only for standalone builds and NOT in chromium, which instead uses 32 // a custom Mojo wrapper (MojoSharedMemory in chromium's //services/tracing/). 33 class SharedMemoryWindows : public SharedMemory { 34 public: 35 class Factory : public SharedMemory::Factory { 36 public: 37 ~Factory() override; 38 std::unique_ptr<SharedMemory> CreateSharedMemory(size_t) override; 39 }; 40 41 // Create a brand new SHM region. 42 static std::unique_ptr<SharedMemoryWindows> Create(size_t size); 43 static std::unique_ptr<SharedMemoryWindows> Attach(const std::string& key); 44 ~SharedMemoryWindows() override; key()45 const std::string& key() const { return key_; } 46 47 // SharedMemory implementation. start()48 void* start() const override { return start_; } size()49 size_t size() const override { return size_; } 50 51 private: 52 SharedMemoryWindows(void* start, 53 size_t size, 54 std::string, 55 base::ScopedPlatformHandle); 56 SharedMemoryWindows(const SharedMemoryWindows&) = delete; 57 SharedMemoryWindows& operator=(const SharedMemoryWindows&) = delete; 58 59 void* const start_; 60 const size_t size_; 61 std::string key_; 62 base::ScopedPlatformHandle handle_; 63 }; 64 65 } // namespace perfetto 66 67 #endif // OS_WIN 68 69 #endif // SRC_TRACING_IPC_SHARED_MEMORY_WINDOWS_H_ 70