1 /* 2 * Copyright (c) 2023 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 #ifndef _VM_VM_COMPRESSOR_PAGER_INTERNAL_H_ 30 #define _VM_VM_COMPRESSOR_PAGER_INTERNAL_H_ 31 32 #include <sys/cdefs.h> 33 #include <vm/vm_compressor_pager_xnu.h> 34 35 __BEGIN_DECLS 36 #ifdef XNU_KERNEL_PRIVATE 37 38 extern kern_return_t vm_compressor_pager_put( 39 memory_object_t mem_obj, 40 memory_object_offset_t offset, 41 ppnum_t ppnum, 42 void **current_chead, 43 char *scratch_buf, 44 int *compressed_count_delta_p, 45 vm_compressor_options_t flags); 46 47 48 extern unsigned int vm_compressor_pager_state_clr( 49 memory_object_t mem_obj, 50 memory_object_offset_t offset); 51 extern vm_external_state_t vm_compressor_pager_state_get( 52 memory_object_t mem_obj, 53 memory_object_offset_t offset); 54 55 extern void vm_compressor_pager_transfer( 56 memory_object_t dst_mem_obj, 57 memory_object_offset_t dst_offset, 58 memory_object_t src_mem_obj, 59 memory_object_offset_t src_offset); 60 extern memory_object_offset_t vm_compressor_pager_next_compressed( 61 memory_object_t mem_obj, 62 memory_object_offset_t offset); 63 64 __enum_closed_decl(vm_decompress_result_t, int, { 65 DECOMPRESS_SUCCESS_SWAPPEDIN = 1, 66 DECOMPRESS_SUCCESS = 0, 67 DECOMPRESS_NEED_BLOCK = -2, 68 DECOMPRESS_FIRST_FAIL_CODE = -3, 69 DECOMPRESS_FAILED_BAD_Q = -3, 70 DECOMPRESS_FAILED_BAD_Q_FREEZE = -4, 71 DECOMPRESS_FAILED_ALGO_ERROR = -5, 72 DECOMPRESS_FAILED_WKDMD_POPCNT = -6, 73 DECOMPRESS_FAILED_UNMODIFIED = -7, 74 #if HAS_MTE 75 DECOMPRESS_FAILED_TAGS = -8 76 #endif /* HAS_MTE */ 77 }); 78 79 extern bool osenvironment_is_diagnostics(void); 80 extern bool osenvironment_is_device_recovery(void); 81 extern void vm_compressor_init(void); 82 extern bool vm_compressor_is_slot_compressed(int *slot); 83 extern kern_return_t vm_compressor_put(ppnum_t pn, int *slot, void **current_chead, char *scratch_buf, vm_compressor_options_t flags); 84 extern vm_decompress_result_t vm_compressor_get(ppnum_t pn, int *slot, vm_compressor_options_t flags); 85 extern int vm_compressor_free(int *slot, vm_compressor_options_t flags); 86 87 #if CONFIG_TRACK_UNMODIFIED_ANON_PAGES 88 extern int vm_uncompressed_put(ppnum_t pn, int *slot); 89 extern int vm_uncompressed_get(ppnum_t pn, int *slot, vm_compressor_options_t flags); 90 extern int vm_uncompressed_free(int *slot, vm_compressor_options_t flags); 91 #endif /* CONFIG_TRACK_UNMODIFIED_ANON_PAGES */ 92 extern unsigned int vm_compressor_pager_reap_pages(memory_object_t mem_obj, vm_compressor_options_t flags); 93 94 extern void vm_compressor_pager_count(memory_object_t mem_obj, 95 int compressed_count_delta, 96 boolean_t shared_lock, 97 vm_object_t object); 98 99 extern void vm_compressor_transfer(int *dst_slot_p, int *src_slot_p); 100 101 #if CONFIG_FREEZE 102 extern kern_return_t vm_compressor_pager_relocate(memory_object_t mem_obj, memory_object_offset_t mem_offset, void **current_chead); 103 extern kern_return_t vm_compressor_relocate(void **current_chead, int *src_slot_p); 104 extern void vm_compressor_finished_filling(void **current_chead); 105 #endif /* CONFIG_FREEZE */ 106 107 #if DEVELOPMENT || DEBUG 108 extern kern_return_t vm_compressor_pager_inject_error(memory_object_t pager, 109 memory_object_offset_t offset); 110 extern void vm_compressor_inject_error(int *slot); 111 112 extern kern_return_t vm_compressor_pager_dump(memory_object_t mem_obj, char *buf, size_t *size, 113 bool *is_compressor, unsigned int *slot_count); 114 #endif /* DEVELOPMENT || DEBUG */ 115 116 #endif /* XNU_KERNEL_PRIVATE */ 117 __END_DECLS 118 119 #endif /* _VM_VM_COMPRESSOR_PAGER_INTERNAL_H_ */ 120