blob: 2f65415d92634e06b38450562e016c66c04d692d [file] [log] [blame]
Greg Hartman40b88f52017-06-22 15:34:11 -07001#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// Base macros for all layout structures.
19
20#include <type_traits>
21#include "common/vsoc/shm/version.h"
22
Greg Hartmanaca3bc72017-07-17 16:03:45 -070023#define ASSERT_SHM_COMPATIBLE(T, R) \
24 static_assert(sizeof(T) == vsoc::layout::version_info::R::T##_size, \
25 "size changed, update the version"); \
Greg Hartman40b88f52017-06-22 15:34:11 -070026 static_assert(std::is_trivial<T>(), "Class uses features that are unsafe")
27
28#define ASSERT_SHM_CONSTANT_VALUE(T, R) \
29 static_assert(T == vsoc::layout::version_info::R::constant_values::T, \
30 "Constant value changed")
31
32namespace vsoc {
33namespace layout {
Jorge E. Moreirac615b452017-08-07 17:22:44 -070034
35/**
36 * Base class that should be used for all shared memory objects
37 */
38class Base {
39};
40ASSERT_SHM_COMPATIBLE(Base, multi_region);
41
Greg Hartmanffe99fa2017-07-14 14:46:19 -070042/**
43 * Memory is shared between Guest and Host kernels. In some cases we need
44 * flag to indicate which side we're on. In those cases we'll use this
45 * simple structure.
46 *
47 * These are carefully formatted to make Guest and Host a bitfield.
48 */
Jorge E. Moreirac615b452017-08-07 17:22:44 -070049struct Sides : public Base {
Greg Hartmanffe99fa2017-07-14 14:46:19 -070050 static const uint32_t NoSides = 0;
51 static const uint32_t Guest = 1;
52 static const uint32_t Host = 2;
53 static const uint32_t Both = 3;
Greg Hartmana4ff2482017-10-03 16:35:00 -070054#ifdef CUTTLEFISH_HOST
Greg Hartmanffe99fa2017-07-14 14:46:19 -070055 static const uint32_t OurSide = Host;
56 static const uint32_t Peer = Guest;
Greg Hartmana4ff2482017-10-03 16:35:00 -070057#else
58 static const uint32_t OurSide = Guest;
59 static const uint32_t Peer = Host;
Greg Hartmanffe99fa2017-07-14 14:46:19 -070060#endif
61
62 uint32_t value_;
63};
64ASSERT_SHM_COMPATIBLE(Sides, multi_region);
65
Jorge E. Moreirac615b452017-08-07 17:22:44 -070066/**
67 * Base class for all region layout structures.
68 */
69class RegionLayout : public Base {
Greg Hartman40b88f52017-06-22 15:34:11 -070070};
Jorge E. Moreirac615b452017-08-07 17:22:44 -070071ASSERT_SHM_COMPATIBLE(RegionLayout, multi_region);
Greg Hartman40b88f52017-06-22 15:34:11 -070072
Greg Hartmanaca3bc72017-07-17 16:03:45 -070073} // namespace layout
74} // namespace vsoc