#ifndef _SYS_UBC_INTERNAL_H_
#define _SYS_UBC_INTERNAL_H_
#include <sys/appleapiopts.h>
#include <sys/types.h>
#include <sys/kernel_types.h>
#include <sys/ucred.h>
#include <sys/vnode.h>
#include <sys/ubc.h>
#include <sys/mman.h>
#include <sys/codesign.h>
#include <sys/cdefs.h>
#include <kern/locks.h>
#include <mach/memory_object_types.h>
#define UBC_INFO_NULL ((struct ubc_info *) 0)
extern struct zone *ubc_info_zone;
#define MAX_CLUSTERS CONFIG_MAX_CLUSTERS
#define SPARSE_PUSH_LIMIT 4
struct cl_extent {
daddr64_t b_addr;
daddr64_t e_addr;
};
struct cl_wextent {
daddr64_t b_addr;
daddr64_t e_addr;
int io_flags;
};
struct cl_readahead {
lck_mtx_t cl_lockr;
daddr64_t cl_lastr;
daddr64_t cl_maxra;
int cl_ralen;
};
struct cl_writebehind {
lck_mtx_t cl_lockw;
void * cl_scmap;
off_t cl_last_write;
off_t cl_seq_written;
int cl_sparse_pushes;
int cl_sparse_wait;
int cl_number;
struct cl_wextent cl_clusters[MAX_CLUSTERS];
};
struct cs_hash;
uint8_t cs_hash_type(struct cs_hash const *);
struct cs_blob {
struct cs_blob *csb_next;
cpu_type_t csb_cpu_type;
unsigned int csb_flags;
off_t csb_base_offset;
off_t csb_start_offset;
off_t csb_end_offset;
vm_size_t csb_mem_size;
vm_offset_t csb_mem_offset;
vm_address_t csb_mem_kaddr;
unsigned char csb_cdhash[CS_CDHASH_LEN];
const struct cs_hash *csb_hashtype;
vm_size_t csb_hash_pagesize;
vm_size_t csb_hash_pagemask;
vm_size_t csb_hash_pageshift;
vm_size_t csb_hash_firstlevel_pagesize;
const CS_CodeDirectory *csb_cd;
const char *csb_teamid;
const CS_GenericBlob *csb_entitlements_blob;
void * csb_entitlements;
unsigned int csb_signer_type;
unsigned int csb_reconstituted;
unsigned int csb_platform_binary:1;
unsigned int csb_platform_path:1;
};
struct ubc_info {
memory_object_t ui_pager;
memory_object_control_t ui_control;
vnode_t ui_vnode;
kauth_cred_t ui_ucred;
off_t ui_size;
uint32_t ui_flags;
uint32_t cs_add_gen;
struct cl_readahead *cl_rahead;
struct cl_writebehind *cl_wbehind;
struct timespec cs_mtime;
struct cs_blob *cs_blobs;
#if CHECK_CS_VALIDATION_BITMAP
void *cs_valid_bitmap;
uint64_t cs_valid_bitmap_size;
#endif
};
#define UI_NONE 0x00000000
#define UI_HASPAGER 0x00000001
#define UI_INITED 0x00000002
#define UI_HASOBJREF 0x00000004
#define UI_WASMAPPED 0x00000008
#define UI_ISMAPPED 0x00000010
#define UI_MAPBUSY 0x00000020
#define UI_MAPWAITING 0x00000040
#define UI_MAPPEDWRITE 0x00000080
__BEGIN_DECLS
__private_extern__ void ubc_init(void);
__private_extern__ int ubc_umount(mount_t mp);
__private_extern__ void ubc_unmountall(void);
__private_extern__ memory_object_t ubc_getpager(vnode_t);
__private_extern__ void ubc_destroy_named(vnode_t);
__private_extern__ void cluster_release(struct ubc_info *);
__private_extern__ uint32_t cluster_throttle_io_limit(vnode_t, uint32_t *);
#define UBC_FLAGS_NONE 0x0000
#define UBC_HOLDOBJECT 0x0001
#define UBC_FOR_PAGEOUT 0x0002
memory_object_control_t ubc_getobject(vnode_t, int);
int ubc_info_init(vnode_t);
int ubc_info_init_withsize(vnode_t, off_t);
void ubc_info_deallocate(struct ubc_info *);
int ubc_isinuse(vnode_t, int);
int ubc_isinuse_locked(vnode_t, int, int);
int ubc_getcdhash(vnode_t, off_t, unsigned char *);
#ifdef XNU_KERNEL_PRIVATE
int UBCINFOEXISTS(const struct vnode *);
#endif
struct cs_blob;
int ubc_cs_blob_add(vnode_t, cpu_type_t, off_t, vm_address_t *, vm_size_t, struct image_params *, int, struct cs_blob **);
int ubc_cs_sigpup_add(vnode_t, vm_address_t, vm_size_t);
struct cs_blob *ubc_get_cs_blobs(vnode_t);
void ubc_get_cs_mtime(vnode_t, struct timespec *);
int ubc_cs_getcdhash(vnode_t, off_t, unsigned char *);
kern_return_t ubc_cs_blob_allocate(vm_offset_t *, vm_size_t *);
void ubc_cs_blob_deallocate(vm_offset_t, vm_size_t);
boolean_t ubc_cs_is_range_codesigned(vnode_t, mach_vm_offset_t, mach_vm_size_t);
kern_return_t ubc_cs_validation_bitmap_allocate( vnode_t );
void ubc_cs_validation_bitmap_deallocate( vnode_t );
__END_DECLS
#endif