+static zone_t mem_obj_control_zone;
+
+__private_extern__ void
+memory_object_control_bootstrap(void)
+{
+ int i;
+
+ i = (vm_size_t) sizeof (struct memory_object_control);
+ mem_obj_control_zone = zinit (i, 8192*i, 4096, "mem_obj_control");
+ return;
+}
+
+__private_extern__ memory_object_control_t
+memory_object_control_allocate(
+ vm_object_t object)
+{
+ memory_object_control_t control;
+
+ control = (memory_object_control_t)zalloc(mem_obj_control_zone);
+ if (control != MEMORY_OBJECT_CONTROL_NULL)
+ control->object = object;
+ return (control);
+}
+
+__private_extern__ void
+memory_object_control_collapse(
+ memory_object_control_t control,
+ vm_object_t object)
+{
+ assert((control->object != VM_OBJECT_NULL) &&
+ (control->object != object));
+ control->object = object;
+}
+
+__private_extern__ vm_object_t
+memory_object_control_to_vm_object(
+ memory_object_control_t control)
+{
+ if (control == MEMORY_OBJECT_CONTROL_NULL)
+ return VM_OBJECT_NULL;
+
+ return (control->object);
+}
+
+memory_object_control_t
+convert_port_to_mo_control(
+ mach_port_t port)
+{
+ return MEMORY_OBJECT_CONTROL_NULL;
+}
+
+
+mach_port_t
+convert_mo_control_to_port(
+ memory_object_control_t control)
+{
+ return MACH_PORT_NULL;
+}
+
+void
+memory_object_control_reference(
+ memory_object_control_t control)
+{
+ return;
+}
+
+/*
+ * We only every issue one of these references, so kill it
+ * when that gets released (should switch the real reference
+ * counting in true port-less EMMI).
+ */
+void
+memory_object_control_deallocate(
+ memory_object_control_t control)
+{
+ zfree(mem_obj_control_zone, (vm_offset_t)control);
+}
+
+void
+memory_object_control_disable(
+ memory_object_control_t control)
+{
+ assert(control->object != VM_OBJECT_NULL);
+ control->object = VM_OBJECT_NULL;
+}
+
+void
+memory_object_default_reference(
+ memory_object_default_t dmm)
+{
+ ipc_port_make_send(dmm);
+}
+
+void
+memory_object_default_deallocate(
+ memory_object_default_t dmm)
+{
+ ipc_port_release_send(dmm);
+}
+
+memory_object_t
+convert_port_to_memory_object(
+ mach_port_t port)
+{
+ return (MEMORY_OBJECT_NULL);
+}
+
+
+mach_port_t
+convert_memory_object_to_port(
+ memory_object_t object)
+{
+ return (MACH_PORT_NULL);
+}
+
+#ifdef MACH_BSD
+/* remove after component interface available */
+extern int vnode_pager_workaround;
+extern int device_pager_workaround;
+#endif
+
+
+/* Routine memory_object_reference */
+void memory_object_reference(
+ memory_object_t memory_object)
+{
+extern void dp_memory_object_reference(memory_object_t);
+
+#ifdef MACH_BSD
+ extern void vnode_pager_reference(memory_object_t);
+ extern void device_pager_reference(memory_object_t);
+
+ if(memory_object->pager == &vnode_pager_workaround) {
+ vnode_pager_reference(memory_object);
+ } else if(memory_object->pager == &device_pager_workaround) {
+ device_pager_reference(memory_object);
+ } else
+#endif
+ dp_memory_object_reference(memory_object);
+}
+
+/* Routine memory_object_deallocate */
+void memory_object_deallocate(
+ memory_object_t memory_object)
+{
+extern void dp_memory_object_deallocate(memory_object_t);
+
+#ifdef MACH_BSD
+ extern void vnode_pager_deallocate(memory_object_t);
+ extern void device_pager_deallocate(memory_object_t);
+
+ if(memory_object->pager == &vnode_pager_workaround) {
+ vnode_pager_deallocate(memory_object);
+ } else if(memory_object->pager == &device_pager_workaround) {
+ device_pager_deallocate(memory_object);
+ } else
+#endif
+ dp_memory_object_deallocate(memory_object);
+}
+
+
+/* Routine memory_object_init */
+kern_return_t memory_object_init
+(
+ memory_object_t memory_object,
+ memory_object_control_t memory_control,
+ vm_size_t memory_object_page_size
+)
+{
+extern kern_return_t dp_memory_object_init(memory_object_t,
+ memory_object_control_t,
+ vm_size_t);
+#ifdef MACH_BSD
+extern kern_return_t vnode_pager_init(memory_object_t,
+ memory_object_control_t,
+ vm_size_t);
+extern kern_return_t device_pager_init(memory_object_t,
+ memory_object_control_t,
+ vm_size_t);
+
+ if(memory_object->pager == &vnode_pager_workaround) {
+ return vnode_pager_init(memory_object,
+ memory_control,
+ memory_object_page_size);
+ } else if(memory_object->pager == &device_pager_workaround) {
+ return device_pager_init(memory_object,
+ memory_control,
+ memory_object_page_size);
+ } else
+#endif
+ return dp_memory_object_init(memory_object,
+ memory_control,
+ memory_object_page_size);
+}
+
+/* Routine memory_object_terminate */
+kern_return_t memory_object_terminate
+(
+ memory_object_t memory_object
+)
+{
+extern kern_return_t dp_memory_object_terminate(memory_object_t);
+
+#ifdef MACH_BSD
+extern kern_return_t vnode_pager_terminate(memory_object_t);
+extern kern_return_t device_pager_terminate(memory_object_t);
+
+ if(memory_object->pager == &vnode_pager_workaround) {
+ return vnode_pager_terminate(memory_object);
+ } else if(memory_object->pager == &device_pager_workaround) {
+ return device_pager_terminate(memory_object);
+ } else
+#endif
+ return dp_memory_object_terminate(memory_object);
+}
+
+/* Routine memory_object_data_request */
+kern_return_t memory_object_data_request
+(
+ memory_object_t memory_object,
+ memory_object_offset_t offset,
+ vm_size_t length,
+ vm_prot_t desired_access
+)
+{
+extern kern_return_t dp_memory_object_data_request(memory_object_t,
+ memory_object_offset_t, vm_size_t, vm_prot_t);
+
+#ifdef MACH_BSD
+extern kern_return_t vnode_pager_data_request(memory_object_t,
+ memory_object_offset_t, vm_size_t, vm_prot_t);
+extern kern_return_t device_pager_data_request(memory_object_t,
+ memory_object_offset_t, vm_size_t, vm_prot_t);
+
+ if (memory_object->pager == &vnode_pager_workaround) {
+ return vnode_pager_data_request(memory_object,
+ offset,
+ length,
+ desired_access);
+ } else if (memory_object->pager == &device_pager_workaround) {
+ return device_pager_data_request(memory_object,
+ offset,
+ length,
+ desired_access);
+ } else
+#endif
+ return dp_memory_object_data_request(memory_object,
+ offset,
+ length,
+ desired_access);
+}
+
+/* Routine memory_object_data_return */
+kern_return_t memory_object_data_return
+(
+ memory_object_t memory_object,
+ memory_object_offset_t offset,
+ vm_size_t size,
+ boolean_t dirty,
+ boolean_t kernel_copy
+)
+{
+ extern kern_return_t dp_memory_object_data_return(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ boolean_t,
+ boolean_t);
+#ifdef MACH_BSD
+ extern kern_return_t vnode_pager_data_return(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ boolean_t,
+ boolean_t);
+ extern kern_return_t device_pager_data_return(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ boolean_t,
+ boolean_t);
+
+ if (memory_object->pager == &vnode_pager_workaround) {
+ return vnode_pager_data_return(memory_object,
+ offset,
+ size,
+ dirty,
+ kernel_copy);
+ } else if (memory_object->pager == &device_pager_workaround) {
+ return device_pager_data_return(memory_object,
+ offset,
+ size,
+ dirty,
+ kernel_copy);
+ } else
+#endif
+ return dp_memory_object_data_return(memory_object,
+ offset,
+ size,
+ dirty,
+ kernel_copy);
+}
+
+/* Routine memory_object_data_initialize */
+kern_return_t memory_object_data_initialize
+(
+ memory_object_t memory_object,
+ memory_object_offset_t offset,
+ vm_size_t size
+)
+{
+
+ extern kern_return_t dp_memory_object_data_initialize(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t);
+#ifdef MACH_BSD
+ extern kern_return_t vnode_pager_data_initialize(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t);
+ extern kern_return_t device_pager_data_initialize(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t);
+
+ if (memory_object->pager == &vnode_pager_workaround) {
+ return vnode_pager_data_initialize(memory_object,
+ offset,
+ size);
+ } else if (memory_object->pager == &device_pager_workaround) {
+ return device_pager_data_initialize(memory_object,
+ offset,
+ size);
+ } else
+#endif
+ return dp_memory_object_data_initialize(memory_object,
+ offset,
+ size);
+}
+
+/* Routine memory_object_data_unlock */
+kern_return_t memory_object_data_unlock
+(
+ memory_object_t memory_object,
+ memory_object_offset_t offset,
+ vm_size_t size,
+ vm_prot_t desired_access
+)
+{
+ extern kern_return_t dp_memory_object_data_unlock(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ vm_prot_t);
+#ifdef MACH_BSD
+ extern kern_return_t vnode_pager_data_unlock(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ vm_prot_t);
+ extern kern_return_t device_pager_data_unlock(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ vm_prot_t);
+
+ if (memory_object->pager == &vnode_pager_workaround) {
+ return vnode_pager_data_unlock(memory_object,
+ offset,
+ size,
+ desired_access);
+ } else if (memory_object->pager == &device_pager_workaround) {
+ return device_pager_data_unlock(memory_object,
+ offset,
+ size,
+ desired_access);
+ } else
+#endif
+ return dp_memory_object_data_unlock(memory_object,
+ offset,
+ size,
+ desired_access);
+
+}
+
+/* Routine memory_object_synchronize */
+kern_return_t memory_object_synchronize
+(
+ memory_object_t memory_object,
+ memory_object_offset_t offset,
+ vm_size_t size,
+ vm_sync_t sync_flags
+)
+{
+ extern kern_return_t dp_memory_object_data_synchronize(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ vm_sync_t);
+#ifdef MACH_BSD
+ extern kern_return_t vnode_pager_data_synchronize(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ vm_sync_t);
+ extern kern_return_t device_pager_data_synchronize(memory_object_t,
+ memory_object_offset_t,
+ vm_size_t,
+ vm_sync_t);
+
+ if (memory_object->pager == &vnode_pager_workaround) {
+ return vnode_pager_synchronize(
+ memory_object,
+ offset,
+ size,
+ sync_flags);
+ } else if (memory_object->pager == &device_pager_workaround) {
+ return device_pager_synchronize(
+ memory_object,
+ offset,
+ size,
+ sync_flags);
+ } else
+#endif
+ return dp_memory_object_synchronize(
+ memory_object,
+ offset,
+ size,
+ sync_flags);
+}
+
+/* Routine memory_object_unmap */
+kern_return_t memory_object_unmap
+(
+ memory_object_t memory_object
+)
+{
+ extern kern_return_t dp_memory_object_unmap(memory_object_t);
+#ifdef MACH_BSD
+ extern kern_return_t vnode_pager_unmap(memory_object_t);
+ extern kern_return_t device_pager_unmap(memory_object_t);
+
+ if (memory_object->pager == &vnode_pager_workaround) {
+ return vnode_pager_unmap(memory_object);
+ } else if (memory_object->pager == &device_pager_workaround) {
+ return device_pager_unmap(memory_object);
+ } else
+#endif
+ return dp_memory_object_unmap(memory_object);
+}
+
+/* Routine memory_object_create */
+kern_return_t memory_object_create
+(
+ memory_object_default_t default_memory_manager,
+ vm_size_t new_memory_object_size,
+ memory_object_t *new_memory_object
+)
+{
+extern kern_return_t default_pager_memory_object_create(memory_object_default_t,
+ vm_size_t,
+ memory_object_t *);
+
+ return default_pager_memory_object_create(default_memory_manager,
+ new_memory_object_size,
+ new_memory_object);
+}