]> git.saurik.com Git - apple/xnu.git/blame - bsd/vm/dp_backing_file.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / vm / dp_backing_file.c
CommitLineData
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 62#include <kern/zalloc.h>
39037602 63#include <kern/policy_internal.h>
91447636 64
1c79356b 65#include <libkern/libkern.h>
1c79356b 66
91447636
A
67#include <vm/vm_pageout.h>
68#include <vm/vm_map.h>
69#include <vm/vm_kern.h>
1c79356b 70#include <vm/vnode_pager.h>
91447636 71#include <vm/vm_protos.h>
2d21ac55
A
72#if CONFIG_MACF
73#include <security/mac_framework.h>
74#endif
1c79356b 75
fe8ab488
A
76#include <pexpert/pexpert.h>
77
1c79356b 78
55e303ae
A
79/*
80 * Routine: macx_backing_store_recovery
81 * Function:
82 * Syscall interface to set a tasks privilege
0a7de745 83 * level so that it is not subject to
55e303ae
A
84 * macx_backing_store_suspend
85 */
86int
87macx_backing_store_recovery(
39037602 88 __unused struct macx_backing_store_recovery_args *args)
55e303ae 89{
39037602 90 return ENOTSUP;
55e303ae
A
91}
92
93/*
94 * Routine: macx_backing_store_suspend
95 * Function:
0a7de745 96 * Syscall interface to stop new demand for
55e303ae
A
97 * backing store when backing store is low
98 */
99
100int
101macx_backing_store_suspend(
39037602 102 __unused struct macx_backing_store_suspend_args *args)
55e303ae 103{
39037602 104 return ENOTSUP;
55e303ae
A
105}
106
39037602 107
39236c6e 108extern boolean_t compressor_store_stop_compaction;
b0d623f7
A
109
110/*
111 * Routine: macx_backing_store_compaction
112 * Function:
113 * Turn compaction of swap space on or off. This is
0a7de745
A
114 * used during shutdown/restart so that the kernel
115 * doesn't waste time compacting swap files that are
116 * about to be deleted anyway. Compaction is always
117 * on by default when the system comes up and is turned
118 * off when a shutdown/restart is requested. It is
b0d623f7 119 * re-enabled if the shutdown/restart is aborted for any reason.
fe8ab488
A
120 *
121 * This routine assumes macx_lock has been locked by macx_triggers ->
122 * mach_macx_triggers -> macx_backing_store_compaction
b0d623f7
A
123 */
124
125int
126macx_backing_store_compaction(int flags)
127{
128 int error;
129
0a7de745 130 if ((error = suser(kauth_cred_get(), 0))) {
b0d623f7 131 return error;
0a7de745 132 }
b0d623f7
A
133
134 if (flags & SWAP_COMPACT_DISABLE) {
39236c6e
A
135 compressor_store_stop_compaction = TRUE;
136
39037602 137 kprintf("compressor_store_stop_compaction = TRUE\n");
b0d623f7 138 } else if (flags & SWAP_COMPACT_ENABLE) {
39236c6e
A
139 compressor_store_stop_compaction = FALSE;
140
39037602 141 kprintf("compressor_store_stop_compaction = FALSE\n");
b0d623f7
A
142 }
143
144 return 0;
145}
146
147/*
148 * Routine: macx_triggers
149 * Function:
150 * Syscall interface to set the call backs for low and
151 * high water marks.
152 */
153int
154macx_triggers(
155 struct macx_triggers_args *args)
156{
0a7de745 157 int flags = args->flags;
b0d623f7 158
0a7de745
A
159 if (flags & (SWAP_COMPACT_DISABLE | SWAP_COMPACT_ENABLE)) {
160 return macx_backing_store_compaction(flags);
161 }
b0d623f7 162
39037602
A
163 return ENOTSUP;
164}
39236c6e 165
0b4c1975 166
1c79356b
A
167int
168macx_swapon(
39037602 169 __unused struct macx_swapon_args *args)
1c79356b 170{
39037602 171 return ENOTSUP;
1c79356b
A
172}
173
39037602 174
1c79356b
A
175/*
176 * Routine: macx_swapoff
177 * Function:
178 * Syscall interface to remove a file from backing store
179 */
180int
181macx_swapoff(
39037602 182 __unused struct macx_swapoff_args *args)
1c79356b 183{
39037602 184 return ENOTSUP;
1c79356b 185}
91447636
A
186
187/*
188 * Routine: macx_swapinfo
189 * Function:
190 * Syscall interface to get general swap statistics
191 */
39236c6e 192extern uint64_t vm_swap_get_total_space(void);
39236c6e
A
193extern uint64_t vm_swap_get_free_space(void);
194extern boolean_t vm_swap_up;
195
91447636
A
196int
197macx_swapinfo(
0a7de745
A
198 memory_object_size_t *total_p,
199 memory_object_size_t *avail_p,
200 vm_size_t *pagesize_p,
201 boolean_t *encrypted_p)
91447636 202{
39037602 203 if (VM_CONFIG_SWAP_IS_PRESENT) {
39037602
A
204 *total_p = vm_swap_get_total_space();
205 *avail_p = vm_swap_get_free_space();
206 *pagesize_p = (vm_size_t)PAGE_SIZE_64;
207 *encrypted_p = TRUE;
39236c6e 208 } else {
39037602
A
209 *total_p = 0;
210 *avail_p = 0;
211 *pagesize_p = 0;
212 *encrypted_p = FALSE;
91447636 213 }
39037602 214 return 0;
91447636 215}