1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <zircon/types.h>
6 
7 #pragma once
8 
9 namespace inspect {
10 
11 // The size for order 0.
12 constexpr size_t kMinOrderShift = 4;
13 constexpr size_t kMinOrderSize = 1 << kMinOrderShift; // 16 bytes
14 
15 // The total number of orders in the buddy allocator.
16 constexpr size_t kNumOrders = 8;
17 
18 // The size of the maximum order.
19 constexpr size_t kMaxOrderShift = kMinOrderShift + kNumOrders - 1;
20 constexpr size_t kMaxOrderSize = 1 << kMaxOrderShift;
21 
22 // The minimum size for the inspection VMO.
23 constexpr size_t kMinVmoSize = 4096;
24 static_assert(kMinVmoSize >= kMaxOrderSize,
25               "Maximum order size must fit in the smallest VMO");
26 
27 // The magic number for verifying the VMO format.
28 constexpr char kMagicNumber[5] = "INSP";
29 
30 template <typename T>
OrderToSize(T order)31 constexpr size_t OrderToSize(T order) {
32     return kMinOrderSize << order;
33 }
34 
IndexForOffset(size_t offset)35 constexpr size_t IndexForOffset(size_t offset) {
36     return offset / kMinOrderSize;
37 }
38 
39 } // namespace inspect
40