2 * Copyright (c) 1999-2020 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 * Author: Umesh Vaishampayan [umeshv@apple.com]
31 * 05-Aug-1999 umeshv Created.
33 * Header file for Unified Buffer Cache.
37 #ifndef _SYS_UBC_INTERNAL_H_
38 #define _SYS_UBC_INTERNAL_H_
40 #include <sys/appleapiopts.h>
41 #include <sys/types.h>
42 #include <sys/kernel_types.h>
43 #include <sys/ucred.h>
44 #include <sys/vnode.h>
47 #include <sys/codesign.h>
49 #include <sys/cdefs.h>
51 #include <kern/locks.h>
52 #include <mach/memory_object_types.h>
54 #include <libkern/ptrauth_utils.h>
56 #define UBC_INFO_NULL ((struct ubc_info *) 0)
59 extern struct zone
*ubc_info_zone
;
62 * Maximum number of vfs clusters per vnode
64 #define MAX_CLUSTERS CONFIG_MAX_CLUSTERS
66 #define SPARSE_PUSH_LIMIT 4 /* limit on number of concurrent sparse pushes outside of the cl_lockw */
67 /* once we reach this limit, we'll hold the lock */
82 daddr64_t cl_lastr
; /* last block read by client */
83 daddr64_t cl_maxra
; /* last block prefetched by the read ahead */
84 int cl_ralen
; /* length of last prefetch */
87 struct cl_writebehind
{
89 void * cl_scmap
; /* pointer to sparse cluster map */
90 off_t cl_last_write
; /* offset of the end of the last write */
91 off_t cl_seq_written
; /* sequentially written bytes */
92 int cl_sparse_pushes
; /* number of pushes outside of the cl_lockw in progress */
93 int cl_sparse_wait
; /* synchronous push is in progress */
94 int cl_number
; /* number of packed write behind clusters currently valid */
95 struct cl_wextent cl_clusters
[MAX_CLUSTERS
]; /* packed write behind clusters */
100 uint8_t cs_hash_type(struct cs_hash
const *);
103 struct cs_blob
* XNU_PTRAUTH_SIGNED_PTR("cs_blob.csb_next") csb_next
;
104 cpu_type_t csb_cpu_type
;
105 cpu_subtype_t csb_cpu_subtype
;
106 unsigned int csb_flags
;
107 off_t csb_base_offset
; /* Offset of Mach-O binary in fat binary */
108 off_t csb_start_offset
; /* Blob coverage area start, from csb_base_offset */
109 off_t csb_end_offset
; /* Blob coverage area end, from csb_base_offset */
110 vm_size_t csb_mem_size
;
111 vm_offset_t csb_mem_offset
;
112 void * XNU_PTRAUTH_SIGNED_PTR("cs_blob.csb_mem_kaddr") csb_mem_kaddr
;
113 unsigned char csb_cdhash
[CS_CDHASH_LEN
];
114 ptrauth_generic_signature_t csb_cdhash_signature
;
115 const struct cs_hash
*csb_hashtype
;
116 #if CONFIG_SUPPLEMENTAL_SIGNATURES
117 unsigned char csb_linkage
[CS_CDHASH_LEN
];
118 const struct cs_hash
*csb_linkage_hashtype
;
120 int csb_hash_pageshift
;
121 int csb_hash_firstlevel_pageshift
; /* First hash this many bytes, then hash the hashes together */
122 const CS_CodeDirectory
* XNU_PTRAUTH_SIGNED_PTR("cs_blob.csb_cd") csb_cd
;
123 const char * XNU_PTRAUTH_SIGNED_PTR("cs_blob.csb_teamid") csb_teamid
;
124 #if CONFIG_SUPPLEMENTAL_SIGNATURES
125 char * XNU_PTRAUTH_SIGNED_PTR("cs_blob.csb_supplement_teamid") csb_supplement_teamid
;
127 const CS_GenericBlob
* XNU_PTRAUTH_SIGNED_PTR("cs_blob.csb_entitlements_blob") csb_entitlements_blob
; /* raw blob, subrange of csb_mem_kaddr */
128 ptrauth_generic_signature_t csb_entitlements_blob_signature
;
129 void * XNU_PTRAUTH_SIGNED_PTR("cs_blob.csb_entitlements") csb_entitlements
; /* The entitlements as an OSDictionary */
130 unsigned int csb_signer_type
;
131 unsigned int csb_reconstituted
; /* signature has potentially been modified after validation */
132 /* The following two will be replaced by the csb_signer_type. */
133 unsigned int csb_platform_binary
:1;
134 unsigned int csb_platform_path
:1;
139 * The following data structure keeps the information to associate
140 * a vnode to the correspondig VM objects.
143 memory_object_t ui_pager
; /* pager */
144 memory_object_control_t ui_control
; /* VM control for the pager */
145 vnode_t
XNU_PTRAUTH_SIGNED_PTR("ubc_info.ui_vnode") ui_vnode
; /* vnode for this ubc_info */
146 kauth_cred_t ui_ucred
; /* holds credentials for NFS paging */
147 off_t ui_size
; /* file size for the vnode */
148 uint32_t ui_flags
; /* flags */
149 uint32_t cs_add_gen
; /* generation count when csblob was validated */
151 struct cl_readahead
*cl_rahead
; /* cluster read ahead context */
152 struct cl_writebehind
*cl_wbehind
; /* cluster write behind context */
154 struct timespec cs_mtime
; /* modify time of file when
155 * first cs_blob was loaded */
156 struct cs_blob
* XNU_PTRAUTH_SIGNED_PTR("ubc_info.cs_blobs") cs_blobs
; /* for CODE SIGNING */
157 #if CONFIG_SUPPLEMENTAL_SIGNATURES
158 struct cs_blob
* XNU_PTRAUTH_SIGNED_PTR("ubc_info.cs_blob_supplement") cs_blob_supplement
;/* supplemental blob (note that there can only be one supplement) */
160 #if CHECK_CS_VALIDATION_BITMAP
161 void * XNU_PTRAUTH_SIGNED_PTR("ubc_info.cs_valid_bitmap") cs_valid_bitmap
; /* right now: used only for signed files on the read-only root volume */
162 uint64_t cs_valid_bitmap_size
; /* Save original bitmap size in case the file size changes.
163 * In the future, we may want to reconsider changing the
164 * underlying bitmap to reflect the new file size changes.
166 #endif /* CHECK_CS_VALIDATION_BITMAP */
169 /* Defines for ui_flags */
170 #define UI_NONE 0x00000000 /* none */
171 #define UI_HASPAGER 0x00000001 /* has a pager associated */
172 #define UI_INITED 0x00000002 /* newly initialized vnode */
173 #define UI_HASOBJREF 0x00000004 /* hold a reference on object */
174 #define UI_WASMAPPED 0x00000008 /* vnode was mapped */
175 #define UI_ISMAPPED 0x00000010 /* vnode is currently mapped */
176 #define UI_MAPBUSY 0x00000020 /* vnode is being mapped or unmapped */
177 #define UI_MAPWAITING 0x00000040 /* someone waiting for UI_MAPBUSY */
178 #define UI_MAPPEDWRITE 0x00000080 /* it's mapped with PROT_WRITE */
181 * exported primitives for loadable file systems.
186 __private_extern__
int ubc_umount(mount_t mp
);
187 __private_extern__
void ubc_unmountall(void);
188 __private_extern__ memory_object_t
ubc_getpager(vnode_t
);
189 __private_extern__
void ubc_destroy_named(vnode_t
);
192 __private_extern__
void cluster_release(struct ubc_info
*);
193 __private_extern__
uint32_t cluster_throttle_io_limit(vnode_t
, uint32_t *);
196 /* Flags for ubc_getobject() */
197 #define UBC_FLAGS_NONE 0x0000
198 #define UBC_HOLDOBJECT 0x0001
199 #define UBC_FOR_PAGEOUT 0x0002
201 memory_object_control_t
ubc_getobject(vnode_t
, int);
203 int ubc_info_init(vnode_t
);
204 int ubc_info_init_withsize(vnode_t
, off_t
);
205 void ubc_info_deallocate(struct ubc_info
*);
207 int ubc_isinuse(vnode_t
, int);
208 int ubc_isinuse_locked(vnode_t
, int, int);
210 int ubc_getcdhash(vnode_t
, off_t
, unsigned char *);
212 #ifdef XNU_KERNEL_PRIVATE
213 int UBCINFOEXISTS(const struct vnode
*);
214 #endif /* XNU_KERNEL_PRIVATE */
218 int ubc_cs_blob_add(vnode_t
, uint32_t, cpu_type_t
, cpu_subtype_t
, off_t
, vm_address_t
*, vm_size_t
, struct image_params
*, int, struct cs_blob
**);
219 #if CONFIG_SUPPLEMENTAL_SIGNATURES
220 int ubc_cs_blob_add_supplement(vnode_t
, vnode_t
, off_t
, vm_address_t
*, vm_size_t
, struct cs_blob
**);
222 struct cs_blob
*ubc_get_cs_blobs(vnode_t
);
223 #if CONFIG_SUPPLEMENTAL_SIGNATURES
224 struct cs_blob
*ubc_get_cs_supplement(vnode_t
);
226 void ubc_get_cs_mtime(vnode_t
, struct timespec
*);
227 int ubc_cs_getcdhash(vnode_t
, off_t
, unsigned char *);
228 kern_return_t
ubc_cs_blob_allocate(vm_offset_t
*, vm_size_t
*);
229 void ubc_cs_blob_deallocate(vm_offset_t
, vm_size_t
);
230 boolean_t
ubc_cs_is_range_codesigned(vnode_t
, mach_vm_offset_t
, mach_vm_size_t
);
232 kern_return_t
ubc_cs_validation_bitmap_allocate( vnode_t
);
233 void ubc_cs_validation_bitmap_deallocate( vnode_t
);
237 #endif /* _SYS_UBC_INTERNAL_H_ */