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.31 by gbeauche, 2008-01-20T00:38:52Z vs.
Revision 1.32 by asvitkine, 2009-08-11T07:43:46Z

# Line 32 | Line 32
32   #include <windows.h>
33   #endif
34  
35 + #include <errno.h>
36   #include <stdio.h>
37   #include <stdlib.h>
38   #include <string.h>
# Line 151 | Line 152 | static int translate_prot_flags(int prot
152   }
153   #endif
154  
155 + /* Translate Mach return codes to POSIX errno values. */
156 + #ifdef HAVE_MACH_VM
157 + static int vm_error(kern_return_t ret_code)
158 + {
159 +        switch (ret_code) {
160 +                case KERN_SUCCESS:
161 +                        return 0;
162 +                case KERN_INVALID_ADDRESS:
163 +                case KERN_NO_SPACE:
164 +                        return ENOMEM;
165 +                case KERN_PROTECTION_FAILURE:
166 +                        return EACCES;
167 +                default:
168 +                        return EINVAL;
169 +        }
170 + }
171 + #endif
172 +
173   /* Initialize the VM system. Returns 0 if successful, -1 for errors.  */
174  
175   int vm_init(void)
# Line 186 | Line 205 | void vm_exit(void)
205   void * vm_acquire(size_t size, int options)
206   {
207          void * addr;
208 +        
209 +        errno = 0;
210  
211          // VM_MAP_FIXED are to be used with vm_acquire_fixed() only
212          if (options & VM_MAP_FIXED)
# Line 198 | Line 219 | void * vm_acquire(size_t size, int optio
219  
220   #ifdef HAVE_MACH_VM
221          // vm_allocate() returns a zero-filled memory region
222 <        if (vm_allocate(mach_task_self(), (vm_address_t *)&addr, size, TRUE) != KERN_SUCCESS)
222 >        kern_return_t ret_code = vm_allocate(mach_task_self(), (vm_address_t *)&addr, size, TRUE);
223 >        if (ret_code != KERN_SUCCESS) {
224 >                errno = vm_error(ret_code);
225                  return VM_MAP_FAILED;
226 +        }
227   #else
228   #ifdef HAVE_MMAP_VM
229          int fd = zero_fd;
# Line 244 | Line 268 | void * vm_acquire(size_t size, int optio
268  
269   int vm_acquire_fixed(void * addr, size_t size, int options)
270   {
271 +        errno = 0;
272 +        
273          // Fixed mappings are required to be private
274          if (options & VM_MAP_SHARED)
275                  return -1;
# Line 255 | Line 281 | int vm_acquire_fixed(void * addr, size_t
281  
282   #ifdef HAVE_MACH_VM
283          // vm_allocate() returns a zero-filled memory region
284 <        if (vm_allocate(mach_task_self(), (vm_address_t *)&addr, size, 0) != KERN_SUCCESS)
284 >        kern_return_t ret_code = vm_allocate(mach_task_self(), (vm_address_t *)&addr, size, 0);
285 >        if (ret_code != KERN_SUCCESS) {
286 >                errno = vm_error(ret_code);
287                  return -1;
288 +        }
289   #else
290   #ifdef HAVE_MMAP_VM
291          int fd = zero_fd;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines