]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/vm/vm_object.h
xnu-517.3.7.tar.gz
[apple/xnu.git] / osfmk / vm / vm_object.h
index 81a303fb440f58e0db0809ec5b8bfdf145b71085..54fc6f9a9d3aa4b42fe5973a2f92ef8e9e99a2aa 100644 (file)
@@ -3,19 +3,22 @@
  *
  * @APPLE_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.
+ * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * 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. 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@
  */
 #include <kern/queue.h>
 #include <kern/lock.h>
 #include <kern/assert.h>
+#include <kern/ipc_mig.h>
+#include <kern/misc_protos.h>
 #include <kern/macro_help.h>
 #include <ipc/ipc_types.h>
 #include <vm/pmap.h>
-#include <kern/misc_protos.h>
 
 #if    MACH_PAGEMAP
 #include <vm/vm_external.h>
 #endif /* MACH_PAGEMAP */
 
-typedef struct ipc_port *      pager_request_t;
+typedef memory_object_control_t        pager_request_t;
 #define        PAGER_REQUEST_NULL      ((pager_request_t) 0)
 
 /*
  *     Types defined:
  *
  *     vm_object_t             Virtual memory object.
- *
- *     We use "struct ipc_port *" instead of "ipc_port_t"
- *     to avoid include file circularities.
  */
 
 typedef unsigned long long vm_object_size_t;
@@ -124,7 +125,7 @@ struct vm_object {
        struct vm_object        *shadow;        /* My shadow */
        vm_object_offset_t      shadow_offset;  /* Offset into shadow */
 
-       struct ipc_port         *pager;         /* Where to get data */
+       memory_object_t         pager;          /* Where to get data */
        vm_object_offset_t      paging_offset;  /* Offset into memory object */
        pager_request_t         pager_request;  /* Where data comes back */
 
@@ -236,7 +237,7 @@ struct vm_object {
                                                 * an error rather than a
                                                 * zero filled page.
                                                 */
-       /* boolean_t */         phys_contiguous:1;
+       /* boolean_t */         phys_contiguous:1,
                                                /* Memory is wired and
                                                 * guaranteed physically 
                                                 * contiguous.  However
@@ -245,6 +246,12 @@ struct vm_object {
                                                 * memory rules w.r.t pmap
                                                 * access bits.
                                                 */
+       /* boolean_t */         nophyscache:1;
+                                               /* When mapped at the 
+                                                * pmap level, don't allow
+                                                * primary caching. (for
+                                                * I/O)
+                                                */
                                                
 
 
@@ -258,25 +265,33 @@ struct vm_object {
                                                   request queue */
 
        vm_object_offset_t      last_alloc;     /* last allocation offset */
+       vm_object_offset_t      sequential;     /* sequential access size */
        vm_size_t               cluster_size;   /* size of paging cluster */
 #if    MACH_PAGEMAP
        vm_external_map_t       existence_map;  /* bitmap of pages written to
                                                 * backing storage */
 #endif /* MACH_PAGEMAP */
+       vm_offset_t             cow_hint;       /* last page present in     */
+                                               /* shadow but not in object */
 #if    MACH_ASSERT
        struct vm_object        *paging_object; /* object which pages to be
                                                 * swapped out are temporary
                                                 * put in current object
                                                 */
 #endif
+                                       /* hold object lock when altering */
+       unsigned        int                     /* cache WIMG bits         */           
+                       wimg_bits:8,            /* wimg plus some expansion*/
+                       not_in_use:24;
 #ifdef UBC_DEBUG
        queue_head_t            uplq;           /* List of outstanding upls */
 #endif /* UBC_DEBUG */
 };
 
-extern
+__private_extern__
 vm_object_t    kernel_object;          /* the single kernel object */
 
+__private_extern__
 int            vm_object_absent_max;   /* maximum number of absent pages
                                           at a time for each object */
 
@@ -317,33 +332,67 @@ typedef struct msync_req  *msync_req_t;
  *     Declare procedures that operate on VM objects.
  */
 
-extern void            vm_object_bootstrap(void);
+__private_extern__ void                vm_object_bootstrap(void);
 
-extern void            vm_object_init(void);
+__private_extern__ void                vm_object_init(void);
 
-extern vm_object_t     vm_object_allocate(
+__private_extern__ vm_object_t vm_object_allocate(
                                        vm_object_size_t        size);
 
+#if    TASK_SWAPPER
+
+__private_extern__ void        vm_object_res_reference(
+                               vm_object_t             object);
+__private_extern__ void        vm_object_res_deallocate(
+                               vm_object_t             object);
+#define        VM_OBJ_RES_INCR(object) (object)->res_count++
+#define        VM_OBJ_RES_DECR(object) (object)->res_count--
+
+#else  /* TASK_SWAPPER */
+
+#define        VM_OBJ_RES_INCR(object)
+#define        VM_OBJ_RES_DECR(object)
+#define vm_object_res_reference(object)
+#define vm_object_res_deallocate(object)
+
+#endif /* TASK_SWAPPER */
+
+#define vm_object_reference_locked(object)             \
+MACRO_BEGIN                                            \
+               vm_object_t RLObject = (object);        \
+               assert((RLObject)->ref_count > 0);      \
+               (RLObject)->ref_count++;                \
+               vm_object_res_reference(RLObject);      \
+MACRO_END
+
+
 #if    MACH_ASSERT
-extern void            vm_object_reference(
+
+__private_extern__ void                vm_object_reference(
                                        vm_object_t     object);
+
 #else  /* MACH_ASSERT */
+
 #define        vm_object_reference(object)                     \
 MACRO_BEGIN                                            \
-       vm_object_t Object = (object);                  \
-       if (Object) {                                   \
-               vm_object_lock(Object);                 \
-               Object->ref_count++;                    \
-               vm_object_res_reference(Object);        \
-               vm_object_unlock(Object);               \
+       vm_object_t RObject = (object);                 \
+       if (RObject) {                                  \
+               vm_object_lock(RObject);                \
+               vm_object_reference_locked(RObject);    \
+               vm_object_unlock(RObject);              \
        }                                               \
 MACRO_END
+
 #endif /* MACH_ASSERT */
 
-extern void            vm_object_deallocate(
+__private_extern__ void                vm_object_deallocate(
                                        vm_object_t     object);
 
-extern void            vm_object_pmap_protect(
+__private_extern__ kern_return_t vm_object_release_name(
+                                       vm_object_t     object,
+                                       int             flags);
+                                                       
+__private_extern__ void                vm_object_pmap_protect(
                                        vm_object_t             object,
                                        vm_object_offset_t      offset,
                                        vm_size_t               size,
@@ -351,12 +400,18 @@ extern void               vm_object_pmap_protect(
                                        vm_offset_t             pmap_start,
                                        vm_prot_t               prot);
 
-extern void            vm_object_page_remove(
+__private_extern__ void                vm_object_page_remove(
                                        vm_object_t             object,
                                        vm_object_offset_t      start,
                                        vm_object_offset_t      end);
 
-extern boolean_t       vm_object_coalesce(
+__private_extern__ void                vm_object_deactivate_pages(
+                                       vm_object_t             object,
+                                       vm_object_offset_t      offset,
+                                       vm_object_size_t        size,
+                                       boolean_t               kill_page);
+
+__private_extern__ boolean_t   vm_object_coalesce(
                                        vm_object_t             prev_object,
                                        vm_object_t             next_object,
                                        vm_object_offset_t      prev_offset,
@@ -364,28 +419,23 @@ extern boolean_t  vm_object_coalesce(
                                        vm_object_size_t        prev_size,
                                        vm_object_size_t        next_size);
 
-extern boolean_t       vm_object_shadow(
+__private_extern__ boolean_t   vm_object_shadow(
                                        vm_object_t             *object,
                                        vm_object_offset_t      *offset,
                                        vm_object_size_t        length);
 
-extern void            vm_object_collapse(
-                                       vm_object_t     object);
-
-extern vm_object_t     vm_object_lookup(
-                                       ipc_port_t      port);
-
-extern ipc_port_t      vm_object_name(
-                                       vm_object_t     object);
+__private_extern__ void                vm_object_collapse(
+                                       vm_object_t             object,
+                                       vm_object_offset_t      offset);
 
-extern boolean_t       vm_object_copy_quickly(
+__private_extern__ boolean_t   vm_object_copy_quickly(
                                vm_object_t             *_object,
                                vm_object_offset_t      src_offset,
                                vm_object_size_t        size,
                                boolean_t               *_src_needs_copy,
                                boolean_t               *_dst_needs_copy);
 
-extern kern_return_t   vm_object_copy_strategically(
+__private_extern__ kern_return_t       vm_object_copy_strategically(
                                vm_object_t             src_object,
                                vm_object_offset_t      src_offset,
                                vm_object_size_t        size,
@@ -393,23 +443,28 @@ extern kern_return_t      vm_object_copy_strategically(
                                vm_object_offset_t      *dst_offset,
                                boolean_t               *dst_needs_copy);
 
-extern kern_return_t   vm_object_copy_slowly(
+__private_extern__ kern_return_t       vm_object_copy_slowly(
                                vm_object_t             src_object,
                                vm_object_offset_t      src_offset,
                                vm_object_size_t        size,
                                int                     interruptible,
                                vm_object_t             *_result_object);
 
-extern void            vm_object_pager_create(
-                                       vm_object_t     object);
+__private_extern__ vm_object_t vm_object_copy_delayed(
+                               vm_object_t             src_object,
+                               vm_object_offset_t      src_offset,
+                               vm_object_size_t        size);
 
-extern void            vm_object_destroy(
-                                       ipc_port_t      pager);
 
-extern void            vm_object_pager_wakeup(
-                                       ipc_port_t      pager);
 
-extern void            vm_object_page_map(
+__private_extern__ kern_return_t       vm_object_destroy(
+                                       vm_object_t     object,
+                                       kern_return_t   reason);
+
+__private_extern__ void                vm_object_pager_create(
+                                       vm_object_t     object);
+
+__private_extern__ void                vm_object_page_map(
                                vm_object_t     object,
                                vm_object_offset_t      offset,
                                vm_object_size_t        size,
@@ -417,38 +472,48 @@ extern void               vm_object_page_map(
                                        (void *, vm_object_offset_t),
                                        void            *map_fn_data);
 
-#if    TASK_SWAPPER
+__private_extern__ kern_return_t vm_object_upl_request(
+                               vm_object_t             object, 
+                               vm_object_offset_t      offset,
+                               vm_size_t               size,
+                               upl_t                   *upl,
+                               upl_page_info_t         *page_info,
+                               unsigned int            *count,
+                               int                     flags);
+
+__private_extern__ boolean_t vm_object_sync(
+                               vm_object_t             object,
+                               vm_object_offset_t      offset,
+                               vm_size_t               size,
+                               boolean_t               should_flush,
+                               boolean_t               should_return);
 
-extern void            vm_object_res_reference(
-                                       vm_object_t object);
-extern void            vm_object_res_deallocate(
-                                       vm_object_t object);
-#define        VM_OBJ_RES_INCR(object) (object)->res_count++
-#define        VM_OBJ_RES_DECR(object) (object)->res_count--
+__private_extern__ kern_return_t vm_object_update(
+                               vm_object_t             object,
+                               vm_object_offset_t      offset,
+                               vm_size_t               size, /* should be 64 */
+                               memory_object_return_t  should_return,
+                               int                     flags,
+                               vm_prot_t               prot);
 
-#else  /* TASK_SWAPPER */
+__private_extern__ kern_return_t vm_object_lock_request(
+                               vm_object_t             object,
+                               vm_object_offset_t      offset,
+                               vm_object_size_t        size,
+                               memory_object_return_t  should_return,
+                               int                     flags,
+                               vm_prot_t               prot);
 
-#define        VM_OBJ_RES_INCR(object)
-#define        VM_OBJ_RES_DECR(object)
-#define vm_object_res_reference(object)
-#define vm_object_res_deallocate(object)
 
-#endif /* TASK_SWAPPER */
 
-extern vm_object_t     vm_object_enter(
-                                       ipc_port_t              pager,
+__private_extern__ vm_object_t vm_object_enter(
+                                       memory_object_t         pager,
                                        vm_object_size_t        size,
                                        boolean_t               internal,
                                        boolean_t               init,
                                        boolean_t               check_named);
 
 
-extern vm_object_t     vm_object_copy_delayed(
-                               vm_object_t             src_object,
-                               vm_object_offset_t      src_offset,
-                               vm_object_size_t        size);
-
-
 /*
  *     Event waiting handling
  */
@@ -463,17 +528,21 @@ extern vm_object_t        vm_object_copy_delayed(
 #define        VM_OBJECT_EVENT_CACHING                 7
 
 #define        vm_object_assert_wait(object, event, interruptible)             \
-       MACRO_BEGIN                                                     \
-       (object)->all_wanted |= 1 << (event);                           \
-       assert_wait((event_t)((vm_offset_t)(object)+(event)),(interruptible)); \
-       MACRO_END
+       (((object)->all_wanted |= 1 << (event)),                        \
+        assert_wait((event_t)((vm_offset_t)(object)+(event)),(interruptible)))
 
 #define        vm_object_wait(object, event, interruptible)                    \
-       MACRO_BEGIN                                                     \
-       vm_object_assert_wait((object),(event),(interruptible));        \
-       vm_object_unlock(object);                                       \
-       thread_block((void (*)(void)) 0);                               \
-       MACRO_END
+       (vm_object_assert_wait((object),(event),(interruptible)),       \
+       vm_object_unlock(object),                                       \
+       thread_block(THREAD_CONTINUE_NULL))                             \
+
+#define thread_sleep_vm_object(object, event, interruptible)           \
+       thread_sleep_mutex((event_t)(event), &(object)->Lock, (interruptible))
+
+#define vm_object_sleep(object, event, interruptible)                  \
+       (((object)->all_wanted |= 1 << (event)),                        \
+        thread_sleep_vm_object((object),                               \
+               ((vm_offset_t)(object)+(event)), (interruptible)))
 
 #define        vm_object_wakeup(object, event)                                 \
        MACRO_BEGIN                                                     \
@@ -511,13 +580,13 @@ extern vm_object_t        vm_object_copy_delayed(
 #define                vm_object_paging_wait(object, interruptible)            \
        MACRO_BEGIN                                                     \
        while ((object)->paging_in_progress != 0) {                     \
-               vm_object_wait( (object),                               \
+               wait_result_t  _wr;                                     \
+                                                                       \
+               _wr = vm_object_sleep((object),                         \
                                VM_OBJECT_EVENT_PAGING_IN_PROGRESS,     \
                                (interruptible));                       \
-               vm_object_lock(object);                                 \
                                                                        \
-               /*XXX if ((interruptible) &&    */                      \
-                   /*XXX (current_thread()->wait_result != THREAD_AWAKENED))*/ \
+               /*XXX if ((interruptible) && (_wr != THREAD_AWAKENED))*/\
                        /*XXX break; */                                 \
        }                                                               \
        MACRO_END