From e34814b27b4a5b80761c166d5827d1c9177fd1fe Mon Sep 17 00:00:00 2001
From: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date: Fri, 27 Aug 2010 01:24:30 +0200
Subject: Keep a reference on objects to preserve their content.

Modify tmpfs to keep a reference (by mapping it into its
own space) to each memory object created by the user, so they don't get
inmediately terminated at the end of the current operation.

* tmpfs/tmpfs.h (struct disknode): Add `memref' field.
* tmpfs/node.c (diskfs_get_filemap): vm_map() the first page of the
newly-allocated object, store in `memref' field.
(diskfs_free_node) vm_deallocate the page pointed by `memref' field.
---
 tmpfs/node.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

(limited to 'tmpfs/node.c')

diff --git a/tmpfs/node.c b/tmpfs/node.c
index 55a45723..c127412e 100644
--- a/tmpfs/node.c
+++ b/tmpfs/node.c
@@ -61,8 +61,10 @@ diskfs_free_node (struct node *np, mode_t mode)
   switch (np->dn->type)
     {
     case DT_REG:
-      if (np->dn->u.reg.memobj != MACH_PORT_NULL)
+      if (np->dn->u.reg.memobj != MACH_PORT_NULL) {
+	vm_deallocate (mach_task_self (), np->dn->u.reg.memref, 4096);
 	mach_port_deallocate (mach_task_self (), np->dn->u.reg.memobj);
+      }	
       break;
     case DT_DIR:
       assert (np->dn->u.dir.entries == 0);
@@ -500,6 +502,13 @@ diskfs_get_filemap (struct node *np, vm_prot_t prot)
 	 past the specified size of the file.  */
       err = default_pager_object_set_size (np->dn->u.reg.memobj,
 					   np->allocsize);
+      assert_perror (err);
+      
+      /* XXX we need to keep a reference to the object, or GNU Mach
+	 could try to terminate it while cleaning object cache */
+      vm_map (mach_task_self (), &np->dn->u.reg.memref, 4096, 0, 1,
+	      np->dn->u.reg.memobj, 0, 0, VM_PROT_NONE, VM_PROT_NONE,
+	      VM_INHERIT_NONE);
     }
 
   /* XXX always writable */
-- 
cgit v1.2.3