ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/vm_alloc.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/vm_alloc.cpp (file contents):
Revision 1.2 by cebix, 2001-07-06T22:37:23Z vs.
Revision 1.3 by gbeauche, 2001-07-07T09:07:38Z

# Line 39 | Line 39
39   #endif
40  
41   #ifdef HAVE_MMAP_VM
42 + static char * next_address = 0;
43   #ifdef HAVE_MMAP_ANON
44   #define map_flags       (MAP_PRIVATE | MAP_ANON)
45   #define zero_fd         -1
# Line 95 | Line 96 | void * vm_acquire(size_t size)
96                  return VM_MAP_FAILED;
97   #else
98   #ifdef HAVE_MMAP_VM
99 <        if ((addr = mmap(0, size, VM_PAGE_DEFAULT, map_flags, zero_fd, 0)) == MAP_FAILED)
99 >        if ((addr = mmap(next_address, size, VM_PAGE_DEFAULT, map_flags, zero_fd, 0)) == MAP_FAILED)
100                  return VM_MAP_FAILED;
101          
102 +        next_address = (char *)addr + size;
103 +        
104          // Since I don't know the standard behavior of mmap(), zero-fill here
105          if (memset(addr, 0, size) != addr)
106                  return VM_MAP_FAILED;
# Line 154 | Line 157 | int vm_acquire_fixed(void * addr, size_t
157  
158   int vm_release(void * addr, size_t size)
159   {
160 +        // Safety check: don't try to release memory that was not allocated
161 +        if (addr == VM_MAP_FAILED)
162 +                return 0;
163 +
164   #ifdef HAVE_MACH_VM
165          int ret_code = vm_deallocate(mach_task_self(), (vm_address_t)addr, size);
166          return ret_code == KERN_SUCCESS ? 0 : -1;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines