| 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 |
| 36 | class IOMemoryDescriptor; |
| 37 | typedef IOMemoryDescriptor * IOSKMemoryRef; |
| 38 | class IOSKArena; |
| 39 | typedef IOSKArena * IOSKArenaRef; |
| 40 | class IOSKRegion; |
| 41 | typedef IOSKRegion * IOSKRegionRef; |
| 42 | class IOSKMapper; |
| 43 | typedef IOSKMapper * IOSKMapperRef; |
| 44 | #define IOSK_CONSUMED LIBKERN_CONSUMED |
| 45 | #else /* !__cplusplus */ |
| 46 | typedef struct IOMemoryDescriptor * IOSKMemoryRef; |
| 47 | typedef struct IOSKArena * IOSKArenaRef; |
| 48 | typedef struct IOSKRegion * IOSKRegionRef; |
| 49 | typedef struct IOSKMapper * IOSKMapperRef; |
| 50 | #define IOSK_CONSUMED |
| 51 | #endif /* !__cplusplus */ |
| 52 | |
| 53 | typedef IOSKMemoryRef IOSKMemoryDescriptor; |
| 54 | |
| 55 | #if defined(__x86_64__) && defined(__cplusplus) |
| 56 | const OSSymbol * IOSKCopyKextIdentifierWithAddress( vm_address_t address ); |
| 57 | #endif |
| 58 | |
| 59 | #ifdef XNU_KERNEL_PRIVATE |
| 60 | #ifdef __cplusplus |
| 61 | class IOMemoryMap; |
| 62 | typedef IOMemoryMap * IOSKMemoryMapRef; |
| 63 | #else /* !__cplusplus */ |
| 64 | typedef struct IOMemoryMap * IOSKMemoryMapRef; |
| 65 | #endif /* !__cplusplus */ |
| 66 | |
| 67 | typedef IOSKMemoryRef IOSKMemoryArrayRef; |
| 68 | typedef IOSKMemoryRef IOSKMemoryBufferRef; |
| 69 | typedef uint32_t IOSKSize; |
| 70 | typedef uint32_t IOSKIndex; |
| 71 | typedef uint32_t IOSKCount; |
| 72 | typedef uint32_t IOSKOffset; |
| 73 | |
| 74 | typedef 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 | |
| 86 | typedef struct { |
| 87 | boolean_t noRedirect; |
| 88 | } IOSKRegionSpec; |
| 89 | |
| 90 | __BEGIN_DECLS |
| 91 | |
| 92 | IOSKMemoryBufferRef IOSKMemoryBufferCreate( mach_vm_size_t capacity, |
| 93 | const IOSKMemoryBufferSpec * spec, |
| 94 | mach_vm_address_t * kvaddr ); |
| 95 | |
| 96 | IOSKMemoryArrayRef IOSKMemoryArrayCreate( const IOSKMemoryRef refs[__counted_by(count)], |
| 97 | uint32_t count ); |
| 98 | |
| 99 | void IOSKMemoryDestroy( IOSK_CONSUMED IOSKMemoryRef reference ); |
| 100 | |
| 101 | IOSKMemoryMapRef IOSKMemoryMapToTask( IOSKMemoryRef reference, |
| 102 | task_t intoTask, |
| 103 | mach_vm_address_t * mapAddr, |
| 104 | mach_vm_size_t * mapSize ); |
| 105 | |
| 106 | IOSKMemoryMapRef IOSKMemoryMapToKernelTask( IOSKMemoryRef reference, |
| 107 | mach_vm_address_t * mapAddr, |
| 108 | mach_vm_size_t * mapSize ); |
| 109 | |
| 110 | void IOSKMemoryMapDestroy( |
| 111 | IOSK_CONSUMED IOSKMemoryMapRef reference ); |
| 112 | |
| 113 | IOReturn IOSKMemoryReclaim( IOSKMemoryRef reference ); |
| 114 | IOReturn IOSKMemoryDiscard( IOSKMemoryRef reference ); |
| 115 | |
| 116 | IOReturn IOSKMemoryWire( IOSKMemoryRef reference ); |
| 117 | IOReturn IOSKMemoryUnwire( IOSKMemoryRef reference ); |
| 118 | |
| 119 | IOSKArenaRef |
| 120 | IOSKArenaCreate( IOSKRegionRef * regionList, IOSKCount regionCount ); |
| 121 | |
| 122 | void |
| 123 | IOSKArenaDestroy( IOSK_CONSUMED IOSKArenaRef arena ); |
| 124 | |
| 125 | void |
| 126 | IOSKArenaRedirect( IOSKArenaRef arena ); |
| 127 | |
| 128 | IOSKRegionRef |
| 129 | IOSKRegionCreate( const IOSKRegionSpec * regionSpec, |
| 130 | IOSKSize segmentSize, IOSKCount segmentCount ); |
| 131 | |
| 132 | void |
| 133 | IOSKRegionDestroy( IOSK_CONSUMED IOSKRegionRef region ); |
| 134 | |
| 135 | IOReturn |
| 136 | IOSKRegionSetBuffer( IOSKRegionRef region, IOSKIndex segmentIndex, |
| 137 | IOSKMemoryBufferRef buffer ); |
| 138 | |
| 139 | void |
| 140 | IOSKRegionClearBuffer( IOSKRegionRef region, IOSKIndex segmentIndex ); |
| 141 | |
| 142 | void |
| 143 | IOSKRegionClearBufferDebug( IOSKRegionRef region, IOSKIndex segmentIndex, |
| 144 | IOSKMemoryBufferRef * prevBufferRef ); |
| 145 | |
| 146 | IOSKMapperRef |
| 147 | IOSKMapperCreate( IOSKArenaRef arena, task_t task ); |
| 148 | |
| 149 | void |
| 150 | IOSKMapperDestroy( IOSK_CONSUMED IOSKMapperRef mapper ); |
| 151 | |
| 152 | void |
| 153 | IOSKMapperRedirect( IOSKMapperRef mapper ); |
| 154 | |
| 155 | IOReturn |
| 156 | IOSKMapperGetAddress( IOSKMapperRef mapper, |
| 157 | mach_vm_address_t * address, mach_vm_size_t * size ); |
| 158 | |
| 159 | boolean_t |
| 160 | IOSKBufferIsWired( IOSKMemoryBufferRef buffer ); |
| 161 | |
| 162 | __END_DECLS |
| 163 | #endif /* XNU_KERNEL_PRIVATE */ |
| 164 | #endif /* KERNEL_PRIVATE */ |
| 165 | #endif /* __IOSKYWALKSUPPORT_H */ |
| 166 | |