2 * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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,
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/proc_internal.h>
39 #include <sys/kauth.h>
42 #include <sys/vnode_internal.h>
43 #include <sys/namei.h>
44 #include <sys/ubc_internal.h>
45 #include <sys/malloc.h>
48 #include <default_pager/default_pager_types.h>
50 #include <security/audit/audit.h>
51 #include <bsm/audit_kevents.h>
53 #include <mach/mach_types.h>
54 #include <mach/host_priv.h>
55 #include <mach/mach_traps.h>
56 #include <mach/boolean.h>
58 #include <kern/kern_types.h>
59 #include <kern/locks.h>
60 #include <kern/host.h>
61 #include <kern/task.h>
62 #include <kern/zalloc.h>
63 #include <kern/policy_internal.h>
65 #include <libkern/libkern.h>
67 #include <vm/vm_pageout.h>
68 #include <vm/vm_map.h>
69 #include <vm/vm_kern.h>
70 #include <vm/vnode_pager.h>
71 #include <vm/vm_protos.h>
73 #include <security/mac_framework.h>
76 #include <pexpert/pexpert.h>
80 * Routine: macx_backing_store_recovery
82 * Syscall interface to set a tasks privilege
83 * level so that it is not subject to
84 * macx_backing_store_suspend
87 macx_backing_store_recovery(
88 __unused
struct macx_backing_store_recovery_args
*args
)
94 * Routine: macx_backing_store_suspend
96 * Syscall interface to stop new demand for
97 * backing store when backing store is low
101 macx_backing_store_suspend(
102 __unused
struct macx_backing_store_suspend_args
*args
)
108 extern boolean_t compressor_store_stop_compaction
;
111 * Routine: macx_backing_store_compaction
113 * Turn compaction of swap space on or off. This is
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
119 * re-enabled if the shutdown/restart is aborted for any reason.
121 * This routine assumes macx_lock has been locked by macx_triggers ->
122 * mach_macx_triggers -> macx_backing_store_compaction
126 macx_backing_store_compaction(int flags
)
130 if ((error
= suser(kauth_cred_get(), 0))) {
134 if (flags
& SWAP_COMPACT_DISABLE
) {
135 compressor_store_stop_compaction
= TRUE
;
137 kprintf("compressor_store_stop_compaction = TRUE\n");
138 } else if (flags
& SWAP_COMPACT_ENABLE
) {
139 compressor_store_stop_compaction
= FALSE
;
141 kprintf("compressor_store_stop_compaction = FALSE\n");
148 * Routine: macx_triggers
150 * Syscall interface to set the call backs for low and
155 struct macx_triggers_args
*args
)
157 int flags
= args
->flags
;
159 if (flags
& (SWAP_COMPACT_DISABLE
| SWAP_COMPACT_ENABLE
)) {
160 return macx_backing_store_compaction(flags
);
169 __unused
struct macx_swapon_args
*args
)
176 * Routine: macx_swapoff
178 * Syscall interface to remove a file from backing store
182 __unused
struct macx_swapoff_args
*args
)
188 * Routine: macx_swapinfo
190 * Syscall interface to get general swap statistics
192 extern uint64_t vm_swap_get_total_space(void);
193 extern uint64_t vm_swap_get_free_space(void);
194 extern boolean_t vm_swap_up
;
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
)
203 if (VM_CONFIG_SWAP_IS_PRESENT
) {
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
;
212 *encrypted_p
= FALSE
;