]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/default_pager/default_pager.c
xnu-2050.7.9.tar.gz
[apple/xnu.git] / osfmk / default_pager / default_pager.c
index 9373974d6a09faab03e3eebc74b2e7b4d55d45f3..21d3667eb5dfc3f9317ba36639ffe4ec67e01dc1 100644 (file)
@@ -1,23 +1,29 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2010 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * @OSF_COPYRIGHT@
@@ -57,7 +63,6 @@
 #include "default_pager_internal.h"
 #include <default_pager/default_pager_object_server.h>
 #include <kern/host.h>
-#include <kern/ledger.h>
 #include <mach/host_info.h>
 #include <mach/host_priv.h>
 #include <mach/vm_map.h>
@@ -80,15 +85,17 @@ int debug_mask = 0;
 vm_size_t      cthread_stack_size = 16 *1024;
 extern vm_size_t cthread_wait_stack_size;
 
+#ifndef MACH_KERNEL
 unsigned long long     vm_page_mask;
 int            vm_page_shift;
+#endif
 
 int            norma_mk;
 
 boolean_t      verbose;
 
 /* task_t default_pager_self; */       /* Our task port. */
-mutex_t                        dpt_lock;       /* lock for the dpt array struct */
+lck_mtx_t                              dpt_lock;       /* lock for the dpt array struct */
 default_pager_thread_t **dpt_array;
 
 memory_object_default_t default_pager_object; /* for memory_object_create. */
@@ -123,11 +130,10 @@ void      default_pager_thread(void *);
 void   default_pager_initialize(void);
 boolean_t      dp_parse_argument(char *);      /* forward; */
 unsigned int   d_to_i(char *);                 /* forward; */
-boolean_t       strprefix(register const char *s1, register const char *s2);
-
 
 extern int vstruct_def_clshift;
 
+struct global_stats global_stats;
 
 /*
  * Initialize and Run the default pager
@@ -275,22 +281,11 @@ start_def_pager( __unused char *bs_device )
 */
 /*
        MACH_PORT_FACE          security_port;
-       MACH_PORT_FACE          root_ledger_wired;
-       MACH_PORT_FACE          root_ledger_paged;
 */
        __unused static char here[] = "main";
 
 
 
-/*
-       default_pager_host_port = ipc_port_make_send(realhost.host_priv_self);
-       master_device_port = ipc_port_make_send(master_device_port);
-       root_ledger_wired = ipc_port_make_send(root_wired_ledger_port);
-       root_ledger_paged = ipc_port_make_send(root_paged_ledger_port);
-       security_port = ipc_port_make_send(realhost.host_security_self);
-*/
-
-
 #if NORMA_VM
        norma_mk = 1;
 #else
@@ -300,8 +295,11 @@ start_def_pager( __unused char *bs_device )
 
        /* setup read buffers, etc */
        default_pager_initialize();
+
+#ifndef MACH_KERNEL    
        default_pager();
-       
+#endif
+
        /* start the backing store monitor, it runs on a callout thread */
        default_pager_backing_store_monitor_callout = 
                thread_call_allocate(default_pager_backing_store_monitor, NULL);
@@ -312,36 +310,20 @@ start_def_pager( __unused char *bs_device )
        return (0);
 }
 
-/*
- * Return TRUE if string 2 is a prefix of string 1.
- */     
-boolean_t       
-strprefix(register const char *s1, register const char *s2)
-{               
-        register int    c;
-                
-        while ((c = *s2++) != '\0') {
-            if (c != *s1++) 
-                return (FALSE);
-        }       
-        return (TRUE);
-}
-
-
 kern_return_t
 default_pager_info(
        memory_object_default_t pager,
        default_pager_info_t    *infop)
 {
-       vm_size_t       pages_total, pages_free;
+       uint64_t        pages_total, pages_free;
 
        if (pager != default_pager_object)
                return KERN_INVALID_ARGUMENT; 
 
        bs_global_info(&pages_total, &pages_free);
 
-       infop->dpi_total_space = ptoa_32(pages_total);
-       infop->dpi_free_space = ptoa_32(pages_free);
+       infop->dpi_total_space = (vm_size_t) ptoa_64(pages_total);
+       infop->dpi_free_space = (vm_size_t) ptoa_64(pages_free);
        infop->dpi_page_size = vm_page_size;
 
        return KERN_SUCCESS;
@@ -353,7 +335,7 @@ default_pager_info_64(
        memory_object_default_t pager,
        default_pager_info_64_t *infop)
 {
-       vm_size_t       pages_total, pages_free;
+       uint64_t        pages_total, pages_free;
 
        if (pager != default_pager_object)
                return KERN_INVALID_ARGUMENT; 
@@ -371,19 +353,30 @@ default_pager_info_64(
        return KERN_SUCCESS;
 }
 
+lck_grp_t              default_pager_lck_grp;
+lck_grp_attr_t default_pager_lck_grp_attr;
+lck_attr_t             default_pager_lck_attr;
+
+
 
 void
-default_pager_initialize()
+default_pager_initialize(void)
 {
        kern_return_t           kr;
        __unused static char    here[] = "default_pager_initialize";
 
+       lck_grp_attr_setdefault(&default_pager_lck_grp_attr);
+       lck_grp_init(&default_pager_lck_grp, "default_pager", &default_pager_lck_grp_attr);
+       lck_attr_setdefault(&default_pager_lck_attr);   
 
        /*
         * Vm variables.
         */
+#ifndef MACH_KERNEL
        vm_page_mask = vm_page_size - 1;
-       vm_page_shift = local_log2(vm_page_size);
+       assert((unsigned int) vm_page_size == vm_page_size);
+       vm_page_shift = local_log2((unsigned int) vm_page_size);
+#endif
 
        /*
         * List of all vstructs.
@@ -391,6 +384,9 @@ default_pager_initialize()
        vstruct_zone = zinit(sizeof(struct vstruct),
                             10000 * sizeof(struct vstruct),
                             8192, "vstruct zone");
+       zone_change(vstruct_zone, Z_CALLERACCT, FALSE);
+       zone_change(vstruct_zone, Z_NOENCRYPT, TRUE);
+
        VSL_LOCK_INIT();
        queue_init(&vstruct_list.vsl_queue);
        vstruct_list.vsl_count = 0;
@@ -418,11 +414,12 @@ default_pager_initialize()
        }
 #else  /* USER_PAGER */
        {
-               int clsize;
+               unsigned int clsize;
                memory_object_default_t dmm;
 
                dmm = default_pager_object;
-               clsize = (vm_page_size << vstruct_def_clshift);
+               assert((unsigned int) vm_page_size == vm_page_size);
+               clsize = ((unsigned int) vm_page_size << vstruct_def_clshift);
                kr = host_default_memory_manager(host_priv_self(), &dmm, clsize);
                if ((kr != KERN_SUCCESS) ||
                    (dmm != MEMORY_OBJECT_DEFAULT_NULL))