]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 2000-2010 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
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. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 A |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ | |
28 | /* | |
29 | * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce | |
30 | * support for mandatory and extensible security protections. This notice | |
31 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
32 | * Version 2.0. | |
1c79356b A |
33 | */ |
34 | ||
1c79356b A |
35 | #include <sys/param.h> |
36 | #include <sys/systm.h> | |
37 | #include <sys/lock.h> | |
91447636 A |
38 | #include <sys/proc_internal.h> |
39 | #include <sys/kauth.h> | |
1c79356b A |
40 | #include <sys/buf.h> |
41 | #include <sys/uio.h> | |
91447636 | 42 | #include <sys/vnode_internal.h> |
1c79356b | 43 | #include <sys/namei.h> |
91447636 A |
44 | #include <sys/ubc_internal.h> |
45 | #include <sys/malloc.h> | |
6d2010ae | 46 | #include <sys/user.h> |
91447636 A |
47 | |
48 | #include <default_pager/default_pager_types.h> | |
1c79356b | 49 | |
b0d623f7 | 50 | #include <security/audit/audit.h> |
e5568f75 A |
51 | #include <bsm/audit_kevents.h> |
52 | ||
1c79356b | 53 | #include <mach/mach_types.h> |
91447636 A |
54 | #include <mach/host_priv.h> |
55 | #include <mach/mach_traps.h> | |
56 | #include <mach/boolean.h> | |
57 | ||
58 | #include <kern/kern_types.h> | |
fe8ab488 | 59 | #include <kern/locks.h> |
1c79356b | 60 | #include <kern/host.h> |
91447636 | 61 | #include <kern/task.h> |
1c79356b A |
62 | #include <kern/zalloc.h> |
63 | #include <kern/kalloc.h> | |
39037602 | 64 | #include <kern/policy_internal.h> |
91447636 | 65 | |
1c79356b | 66 | #include <libkern/libkern.h> |
1c79356b | 67 | |
91447636 A |
68 | #include <vm/vm_pageout.h> |
69 | #include <vm/vm_map.h> | |
70 | #include <vm/vm_kern.h> | |
1c79356b | 71 | #include <vm/vnode_pager.h> |
91447636 | 72 | #include <vm/vm_protos.h> |
2d21ac55 A |
73 | #if CONFIG_MACF |
74 | #include <security/mac_framework.h> | |
75 | #endif | |
1c79356b | 76 | |
fe8ab488 A |
77 | #include <pexpert/pexpert.h> |
78 | ||
1c79356b | 79 | |
55e303ae A |
80 | /* |
81 | * Routine: macx_backing_store_recovery | |
82 | * Function: | |
83 | * Syscall interface to set a tasks privilege | |
0a7de745 | 84 | * level so that it is not subject to |
55e303ae A |
85 | * macx_backing_store_suspend |
86 | */ | |
87 | int | |
88 | macx_backing_store_recovery( | |
39037602 | 89 | __unused struct macx_backing_store_recovery_args *args) |
55e303ae | 90 | { |
39037602 | 91 | return ENOTSUP; |
55e303ae A |
92 | } |
93 | ||
94 | /* | |
95 | * Routine: macx_backing_store_suspend | |
96 | * Function: | |
0a7de745 | 97 | * Syscall interface to stop new demand for |
55e303ae A |
98 | * backing store when backing store is low |
99 | */ | |
100 | ||
101 | int | |
102 | macx_backing_store_suspend( | |
39037602 | 103 | __unused struct macx_backing_store_suspend_args *args) |
55e303ae | 104 | { |
39037602 | 105 | return ENOTSUP; |
55e303ae A |
106 | } |
107 | ||
39037602 | 108 | |
39236c6e | 109 | extern boolean_t compressor_store_stop_compaction; |
b0d623f7 A |
110 | |
111 | /* | |
112 | * Routine: macx_backing_store_compaction | |
113 | * Function: | |
114 | * Turn compaction of swap space on or off. This is | |
0a7de745 A |
115 | * used during shutdown/restart so that the kernel |
116 | * doesn't waste time compacting swap files that are | |
117 | * about to be deleted anyway. Compaction is always | |
118 | * on by default when the system comes up and is turned | |
119 | * off when a shutdown/restart is requested. It is | |
b0d623f7 | 120 | * re-enabled if the shutdown/restart is aborted for any reason. |
fe8ab488 A |
121 | * |
122 | * This routine assumes macx_lock has been locked by macx_triggers -> | |
123 | * mach_macx_triggers -> macx_backing_store_compaction | |
b0d623f7 A |
124 | */ |
125 | ||
126 | int | |
127 | macx_backing_store_compaction(int flags) | |
128 | { | |
129 | int error; | |
130 | ||
0a7de745 | 131 | if ((error = suser(kauth_cred_get(), 0))) { |
b0d623f7 | 132 | return error; |
0a7de745 | 133 | } |
b0d623f7 A |
134 | |
135 | if (flags & SWAP_COMPACT_DISABLE) { | |
39236c6e A |
136 | compressor_store_stop_compaction = TRUE; |
137 | ||
39037602 | 138 | kprintf("compressor_store_stop_compaction = TRUE\n"); |
b0d623f7 | 139 | } else if (flags & SWAP_COMPACT_ENABLE) { |
39236c6e A |
140 | compressor_store_stop_compaction = FALSE; |
141 | ||
39037602 | 142 | kprintf("compressor_store_stop_compaction = FALSE\n"); |
b0d623f7 A |
143 | } |
144 | ||
145 | return 0; | |
146 | } | |
147 | ||
148 | /* | |
149 | * Routine: macx_triggers | |
150 | * Function: | |
151 | * Syscall interface to set the call backs for low and | |
152 | * high water marks. | |
153 | */ | |
154 | int | |
155 | macx_triggers( | |
156 | struct macx_triggers_args *args) | |
157 | { | |
0a7de745 | 158 | int flags = args->flags; |
b0d623f7 | 159 | |
0a7de745 A |
160 | if (flags & (SWAP_COMPACT_DISABLE | SWAP_COMPACT_ENABLE)) { |
161 | return macx_backing_store_compaction(flags); | |
162 | } | |
b0d623f7 | 163 | |
39037602 A |
164 | return ENOTSUP; |
165 | } | |
39236c6e | 166 | |
0b4c1975 | 167 | |
1c79356b A |
168 | int |
169 | macx_swapon( | |
39037602 | 170 | __unused struct macx_swapon_args *args) |
1c79356b | 171 | { |
39037602 | 172 | return ENOTSUP; |
1c79356b A |
173 | } |
174 | ||
39037602 | 175 | |
1c79356b A |
176 | /* |
177 | * Routine: macx_swapoff | |
178 | * Function: | |
179 | * Syscall interface to remove a file from backing store | |
180 | */ | |
181 | int | |
182 | macx_swapoff( | |
39037602 | 183 | __unused struct macx_swapoff_args *args) |
1c79356b | 184 | { |
39037602 | 185 | return ENOTSUP; |
1c79356b | 186 | } |
91447636 A |
187 | |
188 | /* | |
189 | * Routine: macx_swapinfo | |
190 | * Function: | |
191 | * Syscall interface to get general swap statistics | |
192 | */ | |
39236c6e | 193 | extern uint64_t vm_swap_get_total_space(void); |
39236c6e A |
194 | extern uint64_t vm_swap_get_free_space(void); |
195 | extern boolean_t vm_swap_up; | |
196 | ||
91447636 A |
197 | int |
198 | macx_swapinfo( | |
0a7de745 A |
199 | memory_object_size_t *total_p, |
200 | memory_object_size_t *avail_p, | |
201 | vm_size_t *pagesize_p, | |
202 | boolean_t *encrypted_p) | |
91447636 | 203 | { |
39037602 | 204 | if (VM_CONFIG_SWAP_IS_PRESENT) { |
39037602 A |
205 | *total_p = vm_swap_get_total_space(); |
206 | *avail_p = vm_swap_get_free_space(); | |
207 | *pagesize_p = (vm_size_t)PAGE_SIZE_64; | |
208 | *encrypted_p = TRUE; | |
39236c6e | 209 | } else { |
39037602 A |
210 | *total_p = 0; |
211 | *avail_p = 0; | |
212 | *pagesize_p = 0; | |
213 | *encrypted_p = FALSE; | |
91447636 | 214 | } |
39037602 | 215 | return 0; |
91447636 | 216 | } |