xref: /xnu-10002.61.3/osfmk/mach/dyld_pager.h (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
1 /*
2  * Copyright (c) 2021 Apple Inc. All rights reserved.
3  *
4  * @APPLE_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. Please obtain a copy of the License at
10  * http://www.opensource.apple.com/apsl/ and read it before using this
11  * file.
12  *
13  * The Original Code and all software distributed under the License are
14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18  * Please see the License for the specific language governing rights and
19  * limitations under the License.
20  *
21  * @APPLE_LICENSE_HEADER_END@
22  */
23 /*
24  *
25  *	File: mach/dyld_pager.h
26  *
27  *      protos and struct definitions for the pager that applies dyld fixups.
28  */
29 
30 #ifndef _MACH_DYLD_PAGER_H_
31 #define _MACH_DYLD_PAGER_H_
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <mach/vm_prot.h>
38 #include <mach/mach_types.h>
39 
40 /*
41  * These describe the address regions (mwlr_address, mwlr_size) to be mapped
42  * from the given file (mwlr_fd, mwlr_file_offset) with mwlr_protections.
43  */
44 struct mwl_region {
45 	int                  mwlr_fd;      /* fd of file file to over map */
46 	vm_prot_t            mwlr_protections;/* protections for new overmapping */
47 	uint64_t             mwlr_file_offset;/* offset in file of start of mapping */
48 	mach_vm_address_t    mwlr_address __kernel_data_semantics; /* start address of existing region */
49 	mach_vm_size_t       mwlr_size;    /* size of existing region */
50 };
51 
52 #define MWL_INFO_VERS 7
53 struct mwl_info_hdr {
54 	uint32_t        mwli_version;            /* version of info blob, currently 7 */
55 	uint16_t        mwli_page_size;          /* 0x1000 or 0x4000 (for sanity checking) */
56 	uint16_t        mwli_pointer_format;     /* DYLD_CHAINED_PTR_* value */
57 	uint32_t        mwli_binds_offset;       /* offset within this blob of bind pointers table */
58 	uint32_t        mwli_binds_count;        /* number of pointers in bind pointers table (for range checks) */
59 	uint32_t        mwli_chains_offset;      /* offset within this blob of dyld_chained_starts_in_image */
60 	uint32_t        mwli_chains_size;        /* size of dyld_chained_starts_in_image */
61 	uint64_t        mwli_slide;              /* slide to add to rebased pointers */
62 	uint64_t        mwli_image_address;      /* add this to rebase offsets includes any slide */
63 	/* followed by the binds pointers and dyld_chained_starts_in_image */
64 };
65 
66 #define MWL_MAX_REGION_COUNT 5  /* data, const, data auth, auth const, objc const */
67 
68 #ifndef KERNEL_PRIVATE
69 
70 extern int __map_with_linking_np(const struct mwl_region regions[], uint32_t regionCount, const struct mwl_info_hdr* blob, uint32_t blobSize);
71 
72 #endif /* KERNEL_PRIVATE */
73 
74 /*
75  * Special value for dyld to use with shared_region_check_np() to prevent anymore use of map_with_linking_np() in a process
76  */
77 #define DYLD_VM_END_MWL (-1ull)
78 
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 #endif /* _MACH_DYLD_PAGER_H_ */
84