1/*
2 * Copyright (c) 2008 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 __OSKEXTPRIVATE_H__
29#define __OSKEXTPRIVATE_H__
30
31#include <CoreFoundation/CoreFoundation.h>
32#include <System/libkern/OSKextLib.h>
33#include <System/libkern/OSKextLibPrivate.h>
34#include <mach-o/arch.h>
35#include <paths.h>
36#include <sys/stat.h>
37
38#include "OSKext.h"
39
40/* If you aren't IOKitUser or kext_tools, you shouldn't be using this
41 * file. Its contents will change without warning.
42 */
43
44#if PRAGMA_MARK
45/********************************************************************/
46#pragma mark Standard System Extensions Folders
47/********************************************************************/
48#endif
49/*
50 * We use "/System/Library/Extensions" and "/Library/Extensions" - 11860417
51 */
52#define _kOSKextNumSystemExtensionsFolders (2)
53
54#define _kOSKextSystemLibraryExtensionsFolder           \
55            "/System/Library/Extensions"
56#define _kOSKextLibraryExtensionsFolder                 \
57            "/Library/Extensions"
58#define _kOSKextAppleInternalLibraryExtensionsFolder    \
59            "/AppleInternal/Library/Extensions"
60
61#if PRAGMA_MARK
62/********************************************************************/
63#pragma mark Kext Cache Folders & Files
64/********************************************************************/
65#endif
66/*********************************************************************
67* All kext cache files now live under /System/Library/Caches in
68* com.apple.kext.caches. The system extensions folders are duplicated
69* under this node, and at their bottom are the individual cache files
70* for id->URL mapping, and for I/O Kit personalities (owned by the
71* kext_tools project, specifically kextd(8) and kextcache(8)).
72*
73* Here's a schematic:
74* ______________________________________________________________________
75* /System/Library/Caches/com.apple.kext.caches/System/Library/Extensions/ ...
76*     ID->URL Cache: KextIdentifiers.plist.gz (OSBundles?)
77*     Personalities Cache: IOKitPersonalities_<arch>.plist.gz
78*
79* System boot caches (prelinked kernel and mkext) are in the
80* com.apple.kext.caches folder. See the kext_tools project for more.
81*********************************************************************/
82#define _kOSKextCachesRootFolder                       \
83            "/System/Library/Caches/com.apple.kext.caches"
84
85#define _kOSKextDirectoryCachesSubfolder   "Directories"
86#define _kOSKextStartupCachesSubfolder     "Startup"
87
88#define _kOSKextStartupMkextFilename       "Extensions.mkext"
89#define _kOSKextStartupMkextFolderPath     _kOSKextCachesRootFolder       "/" \
90                                           _kOSKextStartupCachesSubfolder
91#define _kOSKextStartupMkextPath           _kOSKextStartupMkextFolderPath "/" \
92                                           _kOSKextStartupMkextFilename
93
94#define _kOSKextIdentifierCacheBasename    "KextIdentifiers"
95#define _kOSKextPrelinkedKernelBasename    "kernelcache"
96
97#define _kOSKextCacheFileMode      (0644)
98#define _kOSKextCacheFileModeMask  (0777)
99#define _kOSKextCacheFolderMode    (0755)
100
101#if PRAGMA_MARK
102/********************************************************************/
103#pragma mark Cache Functions
104/********************************************************************/
105#endif
106
107typedef enum {
108    _kOSKextCacheFormatRaw,
109    _kOSKextCacheFormatCFXML,
110    _kOSKextCacheFormatCFBinary,
111    _kOSKextCacheFormatIOXML,
112} _OSKextCacheFormat;
113
114Boolean _OSKextReadCache(
115    CFTypeRef                 folderURLsOrURL,  // CFArray or CFURLRef
116    CFStringRef               cacheName,
117    const NXArchInfo        * arch,
118    _OSKextCacheFormat        format,
119    Boolean                   parseXMLFlag,
120    CFPropertyListRef       * cacheContentsOut);
121Boolean _OSKextCreateFolderForCacheURL(CFURLRef cacheURL);
122Boolean _OSKextWriteCache(
123    CFTypeRef                 folderURLsOrURL,  // CFArray or CFURLRef
124    CFStringRef               cacheName,
125    const NXArchInfo        * arch,
126    _OSKextCacheFormat        format,
127    CFPropertyListRef         plist);
128Boolean _OSKextReadFromIdentifierCacheForFolder(
129    CFURLRef            anURL,
130    CFMutableArrayRef * kextsOut);
131Boolean _OSKextWriteIdentifierCacheForKextsInDirectory(
132    CFArrayRef kextArray,
133    CFURLRef   directoryURL,
134    Boolean    forceFlag);
135CFArrayRef _OSKextCopyKernelRequests(void);
136OSReturn _OSKextSendResource(
137    CFDictionaryRef request,
138    OSReturn        requestResult,
139    CFDataRef       resource);
140
141#if PRAGMA_MARK
142/********************************************************************/
143#pragma mark URL Utilities
144/********************************************************************/
145#endif
146
147CFStringRef _CFURLCopyAbsolutePath(CFURLRef anURL);
148
149#if PRAGMA_MARK
150/********************************************************************/
151#pragma mark Misc Functions
152/********************************************************************/
153#endif
154
155/* Used by embedded so they can better control which kexts they get.
156 * This must be called when no kexts are opened.
157 */
158void _OSKextSetStrictRecordingByLastOpened(Boolean flag);
159
160
161#if PRAGMA_MARK
162/********************************************************************/
163#pragma mark Logging Macros for Common Errors
164/********************************************************************/
165#endif
166
167#if DEBUG
168
169#define OSKextLogMemError()   \
170    OSKextLog(NULL, \
171        kOSKextLogErrorLevel | kOSKextLogGeneralFlag, \
172        "Error - memory allocation failure, %s, line %d.", __FILE__, __LINE__)
173#define OSKextLogStringError(kext)   \
174    OSKextLog((kext), \
175        kOSKextLogErrorLevel | kOSKextLogGeneralFlag, \
176        "Error - string/URL conversion failure, %s, line %d.", __FILE__, __LINE__)
177
178#else /* DEBUG */
179
180#define OSKextLogMemError()   \
181    OSKextLog(NULL, \
182        kOSKextLogErrorLevel | kOSKextLogGeneralFlag, \
183        "Memory allocation failure.")
184#define OSKextLogStringError(kext)   \
185    OSKextLog((kext), \
186        kOSKextLogErrorLevel | kOSKextLogGeneralFlag, \
187        "String/URL conversion failure.")
188
189#endif /* DEBUG */
190
191#endif /* __OSKEXTPRIVATE_H__ */
192