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