1/*
2 * Copyright (c) 2015-2022 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#ifndef __IOSKYWALKSUPPORT_H
29#define __IOSKYWALKSUPPORT_H
30
31#ifdef KERNEL_PRIVATE
32#include <sys/cdefs.h>
33#include <IOKit/IOReturn.h>
34
35#ifdef __cplusplus
36class IOMemoryDescriptor;
37typedef IOMemoryDescriptor * IOSKMemoryRef;
38class IOSKArena;
39typedef IOSKArena * IOSKArenaRef;
40class IOSKRegion;
41typedef IOSKRegion * IOSKRegionRef;
42class IOSKMapper;
43typedef IOSKMapper * IOSKMapperRef;
44#define IOSK_CONSUMED LIBKERN_CONSUMED
45#else /* !__cplusplus */
46typedef struct IOMemoryDescriptor * IOSKMemoryRef;
47typedef struct IOSKArena * IOSKArenaRef;
48typedef struct IOSKRegion * IOSKRegionRef;
49typedef struct IOSKMapper * IOSKMapperRef;
50#define IOSK_CONSUMED
51#endif /* !__cplusplus */
52
53typedef IOSKMemoryRef IOSKMemoryDescriptor;
54
55#if defined(__x86_64__) && defined(__cplusplus)
56const OSSymbol * IOSKCopyKextIdentifierWithAddress( vm_address_t address );
57#endif
58
59#ifdef XNU_KERNEL_PRIVATE
60#ifdef __cplusplus
61class IOMemoryMap;
62typedef IOMemoryMap * IOSKMemoryMapRef;
63#else /* !__cplusplus */
64typedef struct IOMemoryMap * IOSKMemoryMapRef;
65#endif /* !__cplusplus */
66
67typedef IOSKMemoryRef IOSKMemoryArrayRef;
68typedef IOSKMemoryRef IOSKMemoryBufferRef;
69typedef uint32_t IOSKSize;
70typedef uint32_t IOSKIndex;
71typedef uint32_t IOSKCount;
72typedef uint32_t IOSKOffset;
73
74typedef struct {
75 boolean_t user_writable; /* writable by user task */
76 boolean_t kernel_writable; /* writable by kernel task */
77 boolean_t iodir_in; /* direction: device-to-host */
78 boolean_t iodir_out; /* direction: host-to-device */
79 boolean_t purgeable; /* purgeable (not wired) */
80 boolean_t inhibitCache; /* cache-inhibit */
81 boolean_t physcontig; /* physically contiguous */
82 boolean_t puredata; /* data only, no pointers */
83 boolean_t threadSafe; /* thread safe */
84} IOSKMemoryBufferSpec;
85
86typedef struct {
87 boolean_t noRedirect;
88} IOSKRegionSpec;
89
90__BEGIN_DECLS
91
92IOSKMemoryBufferRef IOSKMemoryBufferCreate( mach_vm_size_t capacity,
93 const IOSKMemoryBufferSpec * spec,
94 mach_vm_address_t * kvaddr );
95
96IOSKMemoryArrayRef IOSKMemoryArrayCreate( const IOSKMemoryRef refs[__counted_by(count)],
97 uint32_t count );
98
99void IOSKMemoryDestroy( IOSK_CONSUMED IOSKMemoryRef reference );
100
101IOSKMemoryMapRef IOSKMemoryMapToTask( IOSKMemoryRef reference,
102 task_t intoTask,
103 mach_vm_address_t * mapAddr,
104 mach_vm_size_t * mapSize );
105
106IOSKMemoryMapRef IOSKMemoryMapToKernelTask( IOSKMemoryRef reference,
107 mach_vm_address_t * mapAddr,
108 mach_vm_size_t * mapSize );
109
110void IOSKMemoryMapDestroy(
111 IOSK_CONSUMED IOSKMemoryMapRef reference );
112
113IOReturn IOSKMemoryReclaim( IOSKMemoryRef reference );
114IOReturn IOSKMemoryDiscard( IOSKMemoryRef reference );
115
116IOReturn IOSKMemoryWire( IOSKMemoryRef reference );
117IOReturn IOSKMemoryUnwire( IOSKMemoryRef reference );
118
119IOSKArenaRef
120IOSKArenaCreate( IOSKRegionRef * regionList, IOSKCount regionCount );
121
122void
123IOSKArenaDestroy( IOSK_CONSUMED IOSKArenaRef arena );
124
125void
126IOSKArenaRedirect( IOSKArenaRef arena );
127
128IOSKRegionRef
129IOSKRegionCreate( const IOSKRegionSpec * regionSpec,
130 IOSKSize segmentSize, IOSKCount segmentCount );
131
132void
133IOSKRegionDestroy( IOSK_CONSUMED IOSKRegionRef region );
134
135IOReturn
136IOSKRegionSetBuffer( IOSKRegionRef region, IOSKIndex segmentIndex,
137 IOSKMemoryBufferRef buffer );
138
139void
140IOSKRegionClearBuffer( IOSKRegionRef region, IOSKIndex segmentIndex );
141
142void
143IOSKRegionClearBufferDebug( IOSKRegionRef region, IOSKIndex segmentIndex,
144 IOSKMemoryBufferRef * prevBufferRef );
145
146IOSKMapperRef
147IOSKMapperCreate( IOSKArenaRef arena, task_t task );
148
149void
150IOSKMapperDestroy( IOSK_CONSUMED IOSKMapperRef mapper );
151
152void
153IOSKMapperRedirect( IOSKMapperRef mapper );
154
155IOReturn
156IOSKMapperGetAddress( IOSKMapperRef mapper,
157 mach_vm_address_t * address, mach_vm_size_t * size );
158
159boolean_t
160IOSKBufferIsWired( IOSKMemoryBufferRef buffer );
161
162__END_DECLS
163#endif /* XNU_KERNEL_PRIVATE */
164#endif /* KERNEL_PRIVATE */
165#endif /* __IOSKYWALKSUPPORT_H */
166