1 /* 2 * Copyright (c) 2024 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29 #pragma once 30 31 #ifndef COMPRESSOR_TESTER 32 #include <pexpert/arm64/board_config.h> 33 #include <vm/vm_compressor_xnu.h> 34 #endif /* COMPRESSOR_TESTER */ 35 36 #if HAS_MTE 37 38 extern uint32_t vm_mte_rle_compress_tags(uint8_t *tags_in_buf, uint32_t in_size, uint8_t *out_buf, uint32_t out_size); 39 extern bool vm_mte_rle_decompress_tags(uint8_t *in_buf, uint32_t in_size, uint8_t *tags_out_buf, uint32_t out_size); 40 extern uint32_t vm_mte_compressed_tags_actual_size(uint32_t mte_size); 41 extern void vm_mte_tags_stats_compressed(uint32_t size_written); 42 43 #if DEVELOPMENT || DEBUG 44 45 struct comp_histogram { 46 #define VM_MTE_C_TAG_COUNT (16) 47 uint64_t cmd_bins[VM_MTE_C_TAG_COUNT]; 48 uint64_t cmd_total; // total number of commands 49 50 // comressed size below and including 64, 128, 192, 256, 320, 384, 448, 512 51 uint64_t comp_size_bins[C_MTE_SIZE / C_SEG_OFFSET_ALIGNMENT_BOUNDARY]; 52 uint64_t same_value_count; 53 }; 54 // generate a histogram of the number of times each command is seen in the input compressed buffer 55 // hist needs to be initialized with zeros before calling this function 56 extern bool vm_mte_rle_comp_histogram(uint8_t *in_buf, uint32_t in_size, struct comp_histogram *hist); 57 58 struct runs_histogram { 59 #define VM_MTE_C_MAX_TAG_RUN ((C_MTE_SIZE * 2) + 1) 60 uint64_t rh_bins[VM_MTE_C_MAX_TAG_RUN]; 61 }; 62 // generate a histogram of the lengths of same-tag runs in the input uncompressed tags buffer 63 // hist needs to be zeroed before the call 64 extern void vm_mte_rle_runs_histogram(uint8_t *in_buf, uint32_t in_size, struct runs_histogram *hist); 65 #endif /* DEVELOPMENT || DEBUG */ 66 67 __enum_closed_decl(vm_mte_c_tags_removal_reason_t, uint32_t, { 68 VM_MTE_C_TAGS_REMOVAL_DECOMPRESSED, 69 VM_MTE_C_TAGS_REMOVAL_FREE, 70 VM_MTE_C_TAGS_REMOVAL_CORRUPT 71 }); 72 73 extern void vm_mte_tags_stats_removed(uint32_t mte_size, vm_mte_c_tags_removal_reason_t reason); 74 75 #endif // HAS_MTE 76