l4-hurd
[Top][All Lists]
Advanced

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

physmem, simple containers


From: Niels Möller
Subject: physmem, simple containers
Date: 22 Jan 2004 23:18:59 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

After reading and thinking some more, I understand Marcus' boot
procedure a little better. My hack for starting the task-server (copy
it into the right place, just like when starting physmem) is wrong.
Instead, the memory should be granted to physmem, and wortel should
get back a container capability.

This capability should then be used to ask physmem to map the memory
to wortel, which can then map it into the new task server process at
the right location. Win: (i) Physmem owns the memory. (ii) We don't
have to copy it. (Actually, we might not need to copy the physmem
image to the right address either, shouldn't it be enough to to use a
different snd base in the grant items when responding to physmem's
page faults? Or is it important that physmem's address space is a
one-to-one mapping of the physical memory?)

Anyway, a missing piece is the actual management of containers in
physmem. Below is some very basic code to keep track of the memory
physmem gets from wortel, and return a container capability.
Containers are contiguous blocks in physmem's address space.

Next needed thing is some physmem requests for mapping the contents of
the container.

The code below is not terribly interesting, but at least it seems to
work. It doesn't examine the grant items it gets from wortel, it justs
trusts that the provided start and end values are correct.

I think it would make sense to split wortel in two threads, one server
thread that serves WORTEL_MSG_* requests and page faults (I suspect
the current arrangement won't work if physmem calls wortel before it
has touched all its memory), and it seems even more necessary if wortel
is to make mmap-related calls to physmem.

Regards,
/Niels

Index: physmem/physmem.c
===================================================================
RCS file: /cvsroot/hurd/hurd-l4/physmem/physmem.c,v
retrieving revision 1.6
diff -u -a -p -r1.6 physmem.c
--- physmem/physmem.c   16 Oct 2003 13:26:45 -0000      1.6
+++ physmem/physmem.c   22 Jan 2004 22:17:44 -0000
@@ -32,6 +32,61 @@
 /* The program name.  */
 char program_name[] = "physmem";

+#define CONTAINER_MAX 100
+#define HANDLE_MAX 100
+
+/* FIXME: For now, a cointainer is a single contiguous block. */
+struct container
+{
+  enum { CONTAINER_FREE, CONTAINER_USED } state;
+  /* Handles referring to this container */
+  unsigned refs;
+  /* Location in physical memory, i.e. our address space */
+  l4_word_t start;
+  l4_word_t end;
+};
+
+struct container
+all_containers[CONTAINER_MAX];
+
+struct container *
+container_alloc(void)
+{
+  unsigned i;
+  for (i = 0; i < CONTAINER_MAX; i++)
+    if (all_containers[i].state == CONTAINER_FREE)
+      {
+       all_containers[i].state = CONTAINER_USED;
+       return all_containers + i;
+      }
+  return NULL;
+};
+
+enum handle_type { HANDLE_FREE, HANDLE_CONTROL, HANDLE_USE };
+struct handle
+{
+  l4_word_t owner; /* A global task id */
+  enum handle_type type;
+  struct container *container;
+};
+
+struct handle
+all_handles[HANDLE_MAX];
+
+struct handle *
+handle_alloc(enum handle_type type, l4_word_t *id)
+{
+  unsigned i;
+  for (i = 0; i < HANDLE_MAX; i++)
+    if (all_handles[i].type == HANDLE_FREE)
+      {
+       all_handles[i].type = type;
+       *id = i;
+       return all_handles + i;
+      }
+  return NULL;
+}
+

 #define WORTEL_MSG_PUTCHAR             1
 #define WORTEL_MSG_PANIC               2
@@ -90,6 +145,12 @@ create_bootstrap_caps (void)
       l4_msg_tag_t tag;
       unsigned int i;

+      l4_word_t start;
+      l4_word_t end;
+      l4_word_t id;
+      struct container *container;
+      struct handle *handle;
+
       l4_msg_clear (&msg);
       l4_set_msg_label (&msg, WORTEL_MSG_GET_CAP_REQUEST);
       /* FIXME: Use real cap_id.  */
@@ -130,9 +191,11 @@ create_bootstrap_caps (void)
               || l4_typed_words (tag) == 0)
        panic ("Invalid format of wortel get cap request reply");

+      start = l4_msg_word (&msg, 1);
+      end = l4_msg_word (&msg, 2);
+
       debug ("Creating cap for 0x%x covering 0x%x to 0x%x:",
-            l4_msg_word (&msg, 0), l4_msg_word (&msg, 1),
-            l4_msg_word (&msg, 2));
+            l4_msg_word (&msg, 0), start, end);

       for (i = 0; i < l4_typed_words (tag); i += 2)
        {
@@ -156,13 +219,26 @@ create_bootstrap_caps (void)
        }
       debug ("\n");

+      container = container_alloc();
+      if (!container)
+       panic ("container_alloc failed!");
+      handle = handle_alloc (HANDLE_CONTROL, &id);
+      if (!handle)
+       panic ("handle_alloc failed!");
+
+      container->start = start;
+      container->end = end;
+      container->refs = 1;
+      /* FIXME: Hardcoded taskid of wortel */
+      handle->owner = 1;
+      handle->container = container;
+
       l4_msg_clear (&msg);
       l4_set_msg_label (&msg, WORTEL_MSG_GET_CAP_REPLY);

       /* FIXME: Use our wortel cap here.  */
       l4_msg_append_word (&msg, 0);
-      /* FIXME: This must return the real capability ID.  */
-      l4_msg_append_word (&msg, 0xa00);
+      l4_msg_append_word (&msg, id);
       l4_msg_load (&msg);
       /* FIXME: Hard coded thread ID.  */
       l4_send (l4_global_id (l4_thread_user_base () + 2, 1));




reply via email to

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