/[hurd]/hurd-l4/deva/mmap.c
ViewVC logotype

Diff of /hurd-l4/deva/mmap.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by marcus, Thu Oct 28 04:12:17 2004 UTC revision 1.2 by neal, Tue Jan 11 18:15:26 2005 UTC
# Line 1  Line 1 
1  /* mmap.c - A simple mmap for anonymous memory allocations in task.  /* mmap.c - A simple mmap for anonymous memory allocations in task.
2     Copyright (C) 2003, 2004 Free Software Foundation, Inc.     Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
3     Written by Marcus Brinkmann.     Written by Neal H. Walfield <neal@gnu.org>.
4    
5     This file is part of the GNU Hurd.     This file is part of the GNU Hurd.
6    
7     The GNU Hurd is free software; you can redistribute it and/or     The GNU Hurd is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public     modify it under the terms of the GNU General Public License as
9     License as published by the Free Software Foundation; either     published by the Free Software Foundation; either version 2, or (at
10     version 2.1 of the License, or (at your option) any later version.     your option) any later version.
11      
12     The GNU Hurd is distributed in the hope that it will be useful,     The GNU Hurd is distributed in the hope that it will be useful, but
13     but WITHOUT ANY WARRANTY; without even the implied warranty of     WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Lesser General Public License for more details.     General Public License for more details.
16      
17     You should have received a copy of the GNU Lesser General Public     You should have received a copy of the GNU General Public License
18     License along with the GNU C Library; if not, write to the Free     along with the GNU Hurd; see the file COPYING.  If not, write to
19     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA     the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
20     02111-1307 USA.  */     USA.  */
21    
22  #if HAVE_CONFIG_H  #if HAVE_CONFIG_H
23  #include <config.h>  #include <config.h>
24  #endif  #endif
25    
26  #include <sys/mman.h>  #include <sys/mman.h>
27  #include <pthread.h>  #include <errno.h>
28    #include <hurd/vm.h>
 #include <hurd/startup.h>  
29    
30  #include "output.h"  #include "output.h"
 #include "physmem-user.h"  
   
   
 /* Initialized by the machine-specific startup-code.  */  
 extern struct hurd_startup_data *__hurd_startup_data;  
   
   
 /* FIXME: All of this is totally lame.  We just know that physmem  
    always allocates new memory for addresses above 0x8000000.  We also  
    know that there is free virtual address space at 0x9000000.  This  
    must be replaced by some real memory manager of course.  */  
 static void *free_vaddr = ((void *) 0x9000000);  
   
 static pthread_mutex_t vaddr_lock = PTHREAD_MUTEX_INITIALIZER;  
   
31    
32  void *  void *
33  mmap (void *address, size_t length, int protect, int flags,  mmap (void *address, size_t length, int protect, int flags,
# Line 58  mmap (void *address, size_t length, int Line 42  mmap (void *address, size_t length, int
42    if (protect != (PROT_READ | PROT_WRITE))    if (protect != (PROT_READ | PROT_WRITE))
43      panic ("mmap called with invalid protection");      panic ("mmap called with invalid protection");
44    
45    /* At this point, we can safely ignore FILEDES and OFFSET.  */    err = hurd_vm_allocate ((uintptr_t *) &address, length, VM_ZEROFILL, 0);
46      if (err)
47    pthread_mutex_lock (&vaddr_lock);      {
48    address = free_vaddr;        errno = err;
49    err = physmem_map (__hurd_startup_data->image.server,        return MAP_FAILED;
50                       __hurd_startup_data->image.cap_handle,      }
51                       ((l4_word_t) address) | L4_FPAGE_FULLY_ACCESSIBLE,    return address;
                       length, address);  
   if (!err)  
     free_vaddr += length;  
   pthread_mutex_unlock (&vaddr_lock);  
   
   return err ? MAP_FAILED : address;  
52  }  }
53    
   
54  int  int
55  munmap (void *addr, size_t length)  munmap (void *addr, size_t length)
56  {  {
57    panic ("munmap() not implemented");    error_t err;
58    
59      /* POSIX says we must round LENGTH up to an even number of pages.
60         If ADDR is unaligned, that is an error (which hurd_vm_deallocate
61         will catch).  */
62      err = hurd_vm_deallocate ((uintptr_t) addr, ((length + getpagesize () - 1)
63                                                   & ~(getpagesize () - 1)));
64      if (err)
65        {
66          errno = err;
67          return -1;
68        }
69    return 0;    return 0;
70  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26