• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 /*
3  * Copyright (C) 2017 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <inttypes.h>
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "common/libs/fs/shared_fd.h"
25 #include "uapi/vsoc_shm.h"
26 
27 namespace ivserver {
28 
29 class VSoCSharedMemory {
30  public:
31   // Region describes a VSoCSharedMem region.
32   struct Region {
33     Region() = default;
RegionRegion34     explicit Region(const char *device_name, const cvd::SharedFD &host_fd,
35                     const cvd::SharedFD &guest_fd)
36         : device_name(device_name), host_fd(host_fd), guest_fd(guest_fd) {}
37     const char *device_name;
38     cvd::SharedFD host_fd;
39     cvd::SharedFD guest_fd;
40   };
41 
42   VSoCSharedMemory() = default;
43   virtual ~VSoCSharedMemory() = default;
44 
45   static std::unique_ptr<VSoCSharedMemory> New(const std::string &name);
46 
47   virtual bool GetEventFdPairForRegion(const std::string &region_name,
48                                        cvd::SharedFD *guest_to_host,
49                                        cvd::SharedFD *host_to_guest) const = 0;
50 
51   virtual const cvd::SharedFD &SharedMemFD() const = 0;
52   virtual const std::vector<Region> &Regions() const = 0;
53 
54  private:
55   VSoCSharedMemory(const VSoCSharedMemory &) = delete;
56   VSoCSharedMemory &operator=(const VSoCSharedMemory &other) = delete;
57 };
58 
59 }  // namespace ivserver
60