• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_H_
18 #define INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_H_
19 
20 #include <stddef.h>
21 
22 #include <memory>
23 
24 #include "perfetto/base/export.h"
25 
26 namespace perfetto {
27 
28 // An abstract interface that models the shared memory region shared between
29 // Service and Producer. The concrete implementation of this is up to the
30 // transport layer. This can be as simple as a malloc()-ed buffer, if both
31 // Producer and Service are hosted in the same process, or some posix shared
32 // memory for the out-of-process case (see src/unix_rpc).
33 // Both this class and the Factory are subclassed by the transport layer, which
34 // will attach platform specific fields to it (e.g., a unix file descriptor).
35 class PERFETTO_EXPORT SharedMemory {
36  public:
37   class PERFETTO_EXPORT Factory {
38    public:
39     virtual ~Factory();
40     virtual std::unique_ptr<SharedMemory> CreateSharedMemory(size_t) = 0;
41   };
42 
43   // The transport layer is expected to tear down the resource associated to
44   // this object region when destroyed.
45   virtual ~SharedMemory();
46 
47   virtual void* start() const = 0;
48   virtual size_t size() const = 0;
49 };
50 
51 }  // namespace perfetto
52 
53 #endif  // INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_H_
54