]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/vm/dp_backing_file.c
xnu-517.7.7.tar.gz
[apple/xnu.git] / bsd / vm / dp_backing_file.c
index e1ff49d7b048c1ae664a27813c59573a25b95d36..cabbf06765130cbec446d7dc9fa2b5334cc62699 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
@@ -31,6 +31,9 @@
 #include <sys/namei.h>
 #include <sys/ubc.h>
 
+#include <bsm/audit_kernel.h>
+#include <bsm/audit_kevents.h>
+
 #include <mach/mach_types.h>
 #include <vm/vm_map.h>
 #include <vm/vm_kern.h>
@@ -65,6 +68,65 @@ struct bs_map                bs_port_table[MAX_BACKING_STORE] = {
 
 #include <kern/assert.h>
 
+/*
+ *     Routine:        macx_backing_store_recovery
+ *     Function:
+ *             Syscall interface to set a tasks privilege
+ *             level so that it is not subject to 
+ *             macx_backing_store_suspend
+ */
+int
+macx_backing_store_recovery(
+       int             pid)
+{
+       int             error;
+       struct proc     *p =  current_proc();
+       boolean_t       funnel_state;
+
+       funnel_state = thread_funnel_set(kernel_flock, TRUE);
+       if ((error = suser(p->p_ucred, &p->p_acflag)))
+               goto backing_store_recovery_return;
+
+       /* for now restrict backing_store_recovery */
+       /* usage to only present task */
+       if(pid != p->p_pid) {
+               error = EINVAL;
+               goto backing_store_recovery_return;
+       }
+
+       task_backing_store_privileged(p->task);
+
+backing_store_recovery_return:
+       (void) thread_funnel_set(kernel_flock, FALSE);
+       return(error);
+}
+
+/*
+ *     Routine:        macx_backing_store_suspend
+ *     Function:
+ *             Syscall interface to stop new demand for 
+ *             backing store when backing store is low
+ */
+
+int
+macx_backing_store_suspend(
+       boolean_t       suspend)
+{
+       int             error;
+       struct proc     *p =  current_proc();
+       boolean_t       funnel_state;
+
+       funnel_state = thread_funnel_set(kernel_flock, TRUE);
+       if ((error = suser(p->p_ucred, &p->p_acflag)))
+               goto backing_store_suspend_return;
+
+       vm_backing_store_disable(suspend);
+
+backing_store_suspend_return:
+       (void) thread_funnel_set(kernel_flock, FALSE);
+       return(error);
+}
+
 /*
  *     Routine:        macx_swapon
  *     Function:
@@ -90,6 +152,9 @@ macx_swapon(
 
        struct vattr    vattr;
 
+       AUDIT_MACH_SYSCALL_ENTER(AUE_SWAPON);
+       AUDIT_ARG(value, priority);
+
        funnel_state = thread_funnel_set(kernel_flock, TRUE);
        ndp = &nd;
 
@@ -104,7 +169,7 @@ macx_swapon(
        /*
         * Get a vnode for the paging area.
         */
-       NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
+       NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1, UIO_USERSPACE,
            filename, p);
 
        if ((error = namei(ndp)))
@@ -202,6 +267,8 @@ macx_swapon(
        /* Mark this vnode as being used for swapfile */
        SET(vp->v_flag, VSWAP);
 
+       ubc_setcred(vp, p);
+
        /*
         * take an extra reference on the vnode to keep
         * vnreclaim() away from this vnode.
@@ -216,6 +283,7 @@ swapon_bailout:
                vrele(vp);
        }
        (void) thread_funnel_set(kernel_flock, FALSE);
+       AUDIT_MACH_SYSCALL_EXIT(error);
        return(error);
 }
 
@@ -239,6 +307,7 @@ macx_swapoff(
        int                     error;
        boolean_t               funnel_state;
 
+       AUDIT_MACH_SYSCALL_ENTER(AUE_SWAPOFF);
        funnel_state = thread_funnel_set(kernel_flock, TRUE);
        backing_store = NULL;
        ndp = &nd;
@@ -249,7 +318,7 @@ macx_swapoff(
        /*
         * Get the vnode for the paging area.
         */
-       NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
+       NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNPATH1, UIO_USERSPACE,
            filename, p);
 
        if ((error = namei(ndp)))
@@ -305,5 +374,6 @@ swapoff_bailout:
                vrele(vp);
 
        (void) thread_funnel_set(kernel_flock, FALSE);
+       AUDIT_MACH_SYSCALL_EXIT(error);
        return(error);
 }