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 = u32::from_le_bytes(*b"INSP");
15
16/// Magic number for the Blob Header block. "BLOB" in UTF-8 little-endian.
17pub const BLOB_HEADER_MAGIC_NUMBER: u32 = u32::from_le_bytes(*b"BLOB");
18
19/// Version number for the Header block, shared by both regular Inspect ("INSP")
20/// and Blob ("BLOB") VMO headers.
21pub const HEADER_VERSION_NUMBER: u32 = 2;
22
23/// Maximum number order of a block.
24pub const NUM_ORDERS: u8 = 8;
25
26/// The shift for order 0.
27pub const MIN_ORDER_SHIFT: usize = 4;
28
29/// The size for order 0.
30pub const MIN_ORDER_SIZE: usize = 1 << MIN_ORDER_SHIFT; // 16 bytes
31
32/// The shift for order NUM_ORDERS-1 (the maximum order)
33pub const MAX_ORDER_SHIFT: usize = MIN_ORDER_SHIFT + (NUM_ORDERS as usize) - 1;
34
35/// The size for order NUM_ORDERS-1 (the maximum order)
36pub const MAX_ORDER_SIZE: usize = 1 << MAX_ORDER_SHIFT;
37
38/// Default number of bytes for the VMO: 256K
39pub const DEFAULT_VMO_SIZE_BYTES: usize = 256 * 1024;
40
41/// Minimum size for the VMO: 4K
42pub const MINIMUM_VMO_SIZE_BYTES: usize = 4 * 1024;
43
44/// Maximum size for a VMO: 100MB
45pub const MAX_VMO_SIZE: usize = 128 * 1024 * 1024;
46
47/// Length in bytes of metadata in the payload of an array block.
48pub const ARRAY_PAYLOAD_METADATA_SIZE_BYTES: usize = 8;
49
50/// The number of bytes in the payload of a STRING_REFERENCE allotted to
51/// the total length.
52pub const STRING_REFERENCE_TOTAL_LENGTH_BYTES: usize = 4;
53
54/// This generation count indicates a VMO is frozen.
55/// It is even to allow creating an inspector that can write to the VMO.
56pub const VMO_FROZEN: u64 = u64::MAX - 1;
57
58/// The order of the header block.
59pub const HEADER_ORDER: u8 = 1;
60
61/// The maximum reference count for a STRING_REFERENCE block (24 bits).
62pub const MAX_REFERENCE_COUNT: u32 = 0xFFFFFF;