bug-hurd
[Top][All Lists]
Advanced

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

Re: providing memory objects to users


From: Neal H. Walfield
Subject: Re: providing memory objects to users
Date: 15 Jun 2002 14:56:57 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2

Marcus Brinkmann <marcus@gnu.org> writes:

> On Fri, Jun 14, 2002 at 10:59:02AM +0200, Neal H. Walfield wrote:
> > > error_t
> > > pager_write_page (struct user_pager_info *upi, vm_offset_t page,
> > >                   vm_address_t buf)
> > > {
> > >   assert (upi->memobj_pages[page / vm_page_size] == (vm_address_t) NULL);
> > >   upi->memobj_pages[page / vm_page_size] = buf;
> > >   return 0;
> > > }
> > 
> > This is fine--assuming that you set upi->memobj_pages[page /
> > vm_page_size] to NULL in pager_read_page.
> 
> I use calloc at upi creation time, and also have an assertion in
> pager_read_page about this.

Someone is clearly confused.


   error_t
   pager_read_page (struct user_pager_info *upi, vm_offset_t page,
                    vm_address_t *buf, int *writelock)
   {
C    assert (upi->memobj_pages[page / vm_page_size] == (vm_address_t) NULL);
   
A    /* This is a read-only medium */
     *writelock = 1;
     
     *buf = (vm_address_t) mmap (0, vm_page_size, PROT_READ|PROT_WRITE,
                                 MAP_ANON, 0, 0);
     return 0;
   }
   
   error_t
   pager_write_page (struct user_pager_info *upi, vm_offset_t page,
                     vm_address_t buf)
   {
D    assert (upi->memobj_pages[page / vm_page_size] == (vm_address_t) NULL);
     upi->memobj_pages[page / vm_page_size] = buf;
     return 0;
   }

   error_t
   pager_unlock_page (struct user_pager_info *pager,
                      vm_offset_t address)
   {
(B)   return 0;
   }

First, you say that this is a read-only medium (A), however, you are
will to unlock the page here (B).  You could reduce a kernel
interaction is you just provided the page to be read/write to begin
with.

Now, I fail to see why you are asserting (C).  Beyond allocating the
array initially with calloc, you never reset the elements to NULL.
Let us consider a possible interaction after the initial
pager_read_page call.  The page is touch and then, time passes.
lalalala.  More time.  lalalala.  The kernel needs memory, it sees
that the page has not been touched and that it is dirty.  It flushes
the page.  pager_write_page is called, (D) is assert and the page is
saved.  Later, the page is faulted back in.  pager_read_page is called
and (C) fails!  So, assuming that you remove (C), you still have a
problem as you have not cleared upi->memobj_pages[page / vm_page_size]
in pager_read_page and this will trigger (D).




reply via email to

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