]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/vm/dp_backing_file.c
xnu-2050.9.2.tar.gz
[apple/xnu.git] / bsd / vm / dp_backing_file.c
index 420238db9ef50b535fe5a13cbac0560d1d63e764..9df1b810effdd830ec465bda7c6dcfb67a778a8b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 #include <sys/vnode_internal.h>
 #include <sys/namei.h>
 #include <sys/ubc_internal.h>
-#include <sys/mount_internal.h>
 #include <sys/malloc.h>
+#include <sys/user.h>
+#if CONFIG_PROTECT
+#include <sys/cprotect.h>
+#endif
 
 #include <default_pager/default_pager_types.h>
 #include <default_pager/default_pager_object.h>
@@ -245,7 +248,7 @@ macx_swapon(
        /*
         * Get a vnode for the paging area.
         */
-       NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1,
+       NDINIT(ndp, LOOKUP, OP_LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1,
               ((IS_64BIT_PROCESS(p)) ? UIO_USERSPACE64 : UIO_USERSPACE32),
               (user_addr_t) args->filename, ctx);
 
@@ -274,6 +277,16 @@ macx_swapon(
        if ((file_size < (off_t)size) && ((error = vnode_setsize(vp, (off_t)size, 0, ctx)) != 0))
                goto swapon_bailout;
 
+#if CONFIG_PROTECT
+       {
+               /* initialize content protection keys manually */
+               if ((error = cp_handle_vnop(vp, CP_WRITE_ACCESS, 0)) != 0) {
+                       goto swapon_bailout;
+               }
+       }
+#endif
+
+
        if (default_pager_init_flag == 0) {
                start_def_pager(NULL);
                default_pager_init_flag = 1;
@@ -306,21 +319,23 @@ macx_swapon(
           goto swapon_bailout;
        }
 
-       if (vp->v_mount->mnt_kern_flag & MNTK_SSD) {
+#if CONFIG_EMBEDDED
+       dp_cluster_size = 1 * PAGE_SIZE;
+#else
+       if ((dp_isssd = vnode_pager_isSSD(vp)) == TRUE) {
                /*
                 * keep the cluster size small since the
                 * seek cost is effectively 0 which means
                 * we don't care much about fragmentation
                 */
-               dp_isssd = TRUE;
                dp_cluster_size = 2 * PAGE_SIZE;
        } else {
                /*
                 * use the default cluster size
                 */
-               dp_isssd = FALSE;
                dp_cluster_size = 0;
        }
+#endif
        kr = default_pager_backing_store_create(default_pager, 
                                        -1, /* default priority */
                                        dp_cluster_size,
@@ -379,6 +394,12 @@ swapon_bailout:
        }
        (void) thread_funnel_set(kernel_flock, FALSE);
        AUDIT_MACH_SYSCALL_EXIT(error);
+
+       if (error)
+               printf("macx_swapon FAILED - %d\n", error);
+       else
+               printf("macx_swapon SUCCESS\n");
+
        return(error);
 }
 
@@ -402,6 +423,8 @@ macx_swapoff(
        int                     error;
        boolean_t               funnel_state;
        vfs_context_t ctx = vfs_context_current();
+       struct uthread  *ut;
+       int                     orig_iopol_disk;
 
        AUDIT_MACH_SYSCALL_ENTER(AUE_SWAPOFF);
 
@@ -415,7 +438,7 @@ macx_swapoff(
        /*
         * Get the vnode for the paging area.
         */
-       NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1,
+       NDINIT(ndp, LOOKUP, OP_LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1,
               ((IS_64BIT_PROCESS(p)) ? UIO_USERSPACE64 : UIO_USERSPACE32),
               (user_addr_t) args->filename, ctx);
 
@@ -447,7 +470,15 @@ macx_swapoff(
        }
        backing_store = (mach_port_t)bs_port_table[i].bs;
 
+       ut = get_bsdthread_info(current_thread());
+
+       orig_iopol_disk = proc_get_thread_selfdiskacc();
+       proc_apply_thread_selfdiskacc(IOPOL_THROTTLE);
+
        kr = default_pager_backing_store_delete(backing_store);
+
+       proc_apply_thread_selfdiskacc(orig_iopol_disk);
+
        switch (kr) {
                case KERN_SUCCESS:
                        error = 0;
@@ -476,6 +507,12 @@ swapoff_bailout:
 
        (void) thread_funnel_set(kernel_flock, FALSE);
        AUDIT_MACH_SYSCALL_EXIT(error);
+
+       if (error)
+               printf("macx_swapoff FAILED - %d\n", error);
+       else
+               printf("macx_swapoff SUCCESS\n");
+
        return(error);
 }