bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] new interface: memory_object_get_proxy


From: Sergey Bugaev
Subject: Re: [PATCH] new interface: memory_object_get_proxy
Date: Mon, 1 Nov 2021 19:47:06 +0300

On Mon, Nov 1, 2021 at 7:13 PM Sergey Bugaev <bugaevc@gmail.com> wrote:
> But again, let's try to get the simple version working first. As I've
> said, with vm_object_pager_create () it kind of works, except it
> doesn't give me the actual data for whatever reason.

Phew, I figured out why that was!

We were not calculating the offset correctly. We have to take into
account the offset of our address inside the entry, not only the
offset of the entry in its memory object (compare to vm_map.c:4694).
That, and also proxies actually don't support non-zero offset, but
they do support non-zero 'start' (I don't know what the difference was
supposed to be between the two).

With this diff (on top of your patch), it finally works sanely for me:

diff --git a/vm/memory_object_proxy.c b/vm/memory_object_proxy.c
index 82b3611c..4343c12e 100644
--- a/vm/memory_object_proxy.c
+++ b/vm/memory_object_proxy.c
@@ -201,6 +201,7 @@ memory_object_get_proxy (task_t task, const
vm_offset_t address,
 {
   kern_return_t ret;
   vm_map_entry_t entry, tmp_entry;
+  vm_object_t object;
   vm_offset_t offset, start;
   ipc_port_t pager;

@@ -217,16 +218,28 @@ memory_object_get_proxy (task_t task, const
vm_offset_t address,
     entry = tmp_entry;
   }

+  if (entry->is_sub_map) {
+    vm_map_unlock_read(task->map);
+    return(KERN_INVALID_ARGUMENT);
+  }
+
   /* Limit the allowed protection and range to the entry ones */
   if (len > entry->vme_end - entry->vme_start) {
     vm_map_unlock_read(task->map);
     return(KERN_INVALID_ARGUMENT);
   }
-
   max_protection &= entry->max_protection;
-  pager = ipc_port_copy_send(entry->object.vm_object->pager);
-  offset = entry->offset;
-  start = 0;
+
+  object = entry->object.vm_object;
+  vm_object_lock(object);
+  /* Create a pager in case this is an internal object that does
+     not yet have one. */
+  vm_object_pager_create(object);
+  pager = ipc_port_copy_send(object->pager);
+  vm_object_unlock(object);
+
+  start = (address - entry->vme_start) + entry->offset;
+  offset = 0;

   vm_map_unlock_read(task->map);

Sergey



reply via email to

[Prev in Thread] Current Thread [Next in Thread]