inspect_format/constants.rs
1// Copyright 2019 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//! Various constants used for Inspect.
6
7/// Bytes per page
8pub const PAGE_SIZE_BYTES: usize = 4096;
9
10/// Size of the a VMO block header.
11pub const HEADER_SIZE_BYTES: usize = 8;
12
13/// Magic number for the Header block. "INSP" in UTF-8 little-endian.
14pub const HEADER_MAGIC_NUMBER: u32 = 0x50534e49;
15
16/// Version number for the Header block.
17pub const HEADER_VERSION_NUMBER: u32 = 2;
18
19/// Maximum number order of a block.
20pub const NUM_ORDERS: u8 = 8;
21
22/// The shift for order 0.
23pub const MIN_ORDER_SHIFT: usize = 4;
24
25/// The size for order 0.
26pub const MIN_ORDER_SIZE: usize = 1 << MIN_ORDER_SHIFT; // 16 bytes
27
28/// The shift for order NUM_ORDERS-1 (the maximum order)
29pub const MAX_ORDER_SHIFT: usize = MIN_ORDER_SHIFT + (NUM_ORDERS as usize) - 1;
30
31/// The size for order NUM_ORDERS-1 (the maximum order)
32pub const MAX_ORDER_SIZE: usize = 1 << MAX_ORDER_SHIFT;
33
34/// Default number of bytes for the VMO: 256K
35pub const DEFAULT_VMO_SIZE_BYTES: usize = 256 * 1024;
36
37/// Minimum size for the VMO: 4K
38pub const MINIMUM_VMO_SIZE_BYTES: usize = 4 * 1024;
39
40/// Maximum size for a VMO: 100MB
41pub const MAX_VMO_SIZE: usize = 128 * 1024 * 1024;
42
43/// Length in bytes of metadata in the payload of an array block.
44pub const ARRAY_PAYLOAD_METADATA_SIZE_BYTES: usize = 8;
45
46/// The number of bytes in the payload of a STRING_REFERENCE allotted to
47/// the total length.
48pub const STRING_REFERENCE_TOTAL_LENGTH_BYTES: usize = 4;
49
50/// This generation count indicates a VMO is frozen.
51/// It is even to allow creating an inspector that can write to the VMO.
52pub const VMO_FROZEN: u64 = u64::MAX - 1;
53
54/// The order of the header block.
55pub const HEADER_ORDER: u8 = 1;